0

I am trying to create an executable JAR from Maven with maven-assembly-plugin. My Jars are getting created but without my source code. I have already mentioned goal as single in POM and creating jar with this command: "mvn clean package assembly:single". But I am still getting this error: "Error: Could not find or load main class com.som.bau.report.MainClass".

enter image description here

Please see below my POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>VFIE_SOM_BAU_Report</groupId> <artifactId>SOM_BAU_Report</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <jdk.version>1.7</jdk.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <downloadSources>true</downloadSources> <downloadJavadocs>false</downloadJavadocs> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4.1</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.som.bau.report.MainClass</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> <!-- Dependencies code goes here ---!> </dependencies> </project> 
5
  • Are you sure your main class is com.som.bau.report.MainClass ? Commented Apr 9, 2018 at 8:18
  • Yes I have main method in this class and it works if I directly execute it from eclipse Commented Apr 9, 2018 at 8:19
  • also attach directory structure in question Commented Apr 9, 2018 at 8:31
  • attached....... Commented Apr 9, 2018 at 9:23
  • @ManishRajput have you checked your target/classes folder, is your .class files there or not ? Commented Apr 9, 2018 at 11:56

2 Answers 2

1

You should append packaging type to root element.

... <modelVersion>4.0.0</modelVersion> <groupId>VFIE_SOM_BAU_Report</groupId> <artifactId>SOM_BAU_Report</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> ... 
Sign up to request clarification or add additional context in comments.

4 Comments

Doesn't packaging default to jar?
İn the target folder there are two jar files. Be sure run right jar.
I am executing the right one. Issue is both of the jars doesn't have my source code
ok. can you list files in jar with jar tf package.jar command then you will check it. is it everything is ok ?
0

I found the solution for it.

Need to add this tag under build tag.

<sourceDirectory>src</sourceDirectory> 

1 Comment

You should have rather put your sources under src/main/java, which is the default assumption from Maven

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.