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 with onejar-maven-plugin
.
Also, maven-shade-plugin
is actively being maintained as opposed to onejar-maven-plugin
which is in the purgatory that is googlecode.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>build-first</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>classpath.to.first.Main</mainClass>
</transformer>
</transformers>
<finalName>first-runnable</finalName>
</configuration>
</execution>
<execution>
<id>build-second</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>classpath.to.second.Main</mainClass>
</transformer>
</transformers>
<finalName>second-runnable</finalName>
</configuration>
</execution>
</executions>
</plugin>