Onejar-maven-plugin collects your application including dependencies, into one executable jar. It’s both easy and works well!
(UPDATED for version 1.3.0. See below.)
If you have ever tried doing this before with Maven, you have probably used maven-assembly-plugin, which would leave the door open for classpath problems!
It would extract all your dependency jars in one directory together with all your class files and all other classpath resources. The problem is that everything ended up in a big mix, with classpath resources possibly overwriting each other. For example, if two dependencies each had a
log4j.properties file in their jar, one
log4j.properties would overwrite the other.
No more of that mess!
Enter maven-onejar-plugin. It lets all your dependency jars stay jars, and your code is in its own jar. All of those jars are put in a bigger jar, which is made executable.
It may sound weird, but it’s quite elegant! Just put this in your
<plugins> tag to make it work:
You also need to add this to the pom: