I am working on my web java project. When I try to run java jar file built by maven, I get an error:
no main manifest attribute, in "project name".
I think the reason is maven can't find my main class. I have created test project with this hierarchy:
/test
/src
/main
Main.java
pom.xml
The pom.xml file contains this:
<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>FirstProject</groupId>
<artifactId>FirstProject</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugin</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<outputDirectory>${basedir}</outputDirectory>
<finalName>server</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Also get this error in test project. I tried to google it, everybody advise to add in pom.xml, but I already have done this...(it is not a solution, in my case). How can I solve this problem?
In a Java project, every executable jar file contains a main method. Usually, it is placed at starting point of the application. To execute a main method by a self-executing jar file, we must have a proper manifest file and wrap it with our project at the proper location.
You might get this error when the Main-Class entry is missing in MANIFEST. MF file. You can put the maven-jar-plugin plugin in pom. xml to fix it.
The manifest attribute specifies the location of the document's cache manifest. HTML5 introduces application cache, which means that a web application is cached, and accessible without an internet connection.
Shade plugin is much easier to use :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>main.Main</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With