Maven have a pretty awesome tutorial in their getting started guide here: http://maven.apache.org/guides/getting-started/index.html
The problem is that if you follow it letter for letter, then run:
java -jar target/<jarname.jar>
you receive a “no main manifest attribute” error.
Stackoverflow has a good answer for this problem, but it took a few readings before I understood what they were saying. Here’s a link to the stackoverflow question:
Open your pom.xml and add the section listed:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
This goes after the URL tag, but before the dependencies tag.
After this, run the following maven command:
mvn clean compile assembly:single
This will output a jar-with-dependencies.jar file in your target\ directory.
Thanks. Your post helped me
HOURS of searching before I found your solution. Thanks! It’s probably saved me yet more hours!
😉
Thanks!!!
You save my day!!!!!!!!!!!!!!!! Thank you so much!!!!!!!!!!!!!!!!
Thanks for this article, saved me time