2009-07-21

Maven how to set the Main-Class in the Manifest

In Java, for a jar to be executed, the easiest way is to set its entry point. This is done by setting the Main-Class in the Manifest. Easy.
Now let's do it with Maven !

First you use your jar, in Maven, you can to configure it this way:
project/build/plugins/plugin
artifactId maven-jar-plugin
version 2.2
configuration
archive
manifestEntries
Main-Class com.comp.proj.main

Now you would like your jar to contain all the dependencies, then you use the maven-assembly-plugin. But it won't take the configuration set in the jar plugin. You have to reconfigure the exact same main-class again. It is redundant OK, but why should it have a different syntax !?!
project/build/plugins/plugin
artifactId maven-assembly-plugin
configuration
archive
manifest
mainClass com.corial.cosma.apptest.apptest

OK, the point is that there are at least two way to configure the Manifest. Either with a free key/value syntax, with Manifest Entries. Or with the class Manifest which has a mainClass element. So it is up to you to be consistent in your POM and not copy everything found on the net ...

Notes:

No comments:

2023 summary

  Life is bigger than what you can imagine.  Still using Roam  http://www.roamresearch.com/  to take notes Still using Mastodon mainly, but ...