Table of contents
Problem
Sometimes you face the following error while runing an executable jar :
No main manifest attribute, in “<APP_NAME>.jar”
Solution
- Main-class property is missing on your jars META-INF/MANIFEST.MF. Correct it by adding the following lines to your pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<build> <plugins> <plugin> <!-- Build an executable JAR --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <mainClass>com.roufid.tutorials.AppTest</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> |
Consider that the the fully qualified name of your Main class is com.roufid.tutorials.AppTest
- Launch a clean install on your application
1mvn clean install - Run your executable jar using the following command :
1java -jar AppTest-0.0.1-SNAPSHOT.jar
Take time to understand !
Since your are running an executable jar file, Java will look for the manifest MANIFEST.MF located under META-INF/ which contains information about the files packaged.
Java must know the main class to run. This information was missing in the MANIFEST.MF. Below the content of this file before adding the maven-jar-plugin :
1 2 3 4 5 |
Manifest-Version: 1.0 Built-By: Radouane ROUFID Build-Jdk: 1.7.0_79 Created-By: Apache Maven 3.3.3 Archiver-Version: Plexus Archiver |
There is no mention of a Main-Class !
We used maven-jar-plugin to handle jar content and manifest configuration, specially adding a Main-Class property to MANIFEST.MF file to specify the project main class. Below the aim of the property :
- <mainClass>com.roufid.tutorials.AppTest</mainClass>
Is to make our Jar executable. You must set here the fully qualified name of your Main class.
The manifest classpath produced using the above configuration would look like this:
1 2 3 4 5 6 |
Manifest-Version: 1.0 Built-By: Radouane ROUFID Build-Jdk: 1.7.0_79 Created-By: Apache Maven 3.3.3 Main-Class: com.roufid.tutorials.AppTest Archiver-Version: Plexus Archiver |