This question already has an answer here:
I have a single maven project that has multiple main classes. I want to generate runnable Jars (that include all dependencies) out of these project. I currently have the following build configuration (using maven.assembly):
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>classpath.to.my.mainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
Is their a way to achive this with maven-assembly? If not, what is the simplest way to achive my goal?
I wasn't able to solve this problem with the
maven-assembly-plugin
in a satisfying way, so I went for a different solution. I used the onejar-maven-plugin:The top answer works if you are not using any configuration (or any resource, for that matter) that gets bundled into your jar file (e.g., configuration for Spring Framework auto-bindings).
Fortunately, this solution also works with
maven-shade-plugin
and you don't have that aforementioned issue withonejar-maven-plugin
.Also,
maven-shade-plugin
is actively being maintained as opposed toonejar-maven-plugin
which is in the purgatory that is googlecode.You can do it. You'll need a separate execution for each artifact that you're building (i.e., give each its own id but you can leave the phase as default), and you'll need to specify the finalName and archive/manifest/mainClass for each.
To specify a little more previous answer that was very helpful to me, you need to add phase package and goal assembly and run mvn run clean package, pom is as follows :