I am having a similar problem to this question. I have tried all the suggestions listed and am still at a loss. My issue is that I am trying to build a maven project and distribute it to other machines, but the jar files are not being populated with a correct Manifest. Each time I build and run I get the following error: no main manifest attribute, in myjar.jar
. Is there some sort of configuration file I need to edit? I just don't know what is going on. I have attempted this fix also, but to no avail.
Right-click the user name package and select New -> Java Main Class... Name your class Menu . Run the project. You will be prompted to select the main class.
Make sure all files are saved first. If you try to run a program where the class containing the main method has not been saved, this can happen. Right-click on the project name (in the Projects explorer), then select Properties > Run - and then make sure the main class is selected there.
Another option is to use the maven shade plugin
. Unlike the maven jar plugin
showed by tigran, the maven shade plugin
includes your dependencies in the generated jar.
A sample usage of the plugin is :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>your.main.Class</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
You can add it into project's pom file, inside <project>
tag:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>your.main.class</mainClass>
</manifest>
</archive>
</configuration>
</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