I have a code base which I want to distribute as jar. It also have dependency on external jars, which I want to bundle in the final jar.
I heard that this can be do
Note: If you are a spring-boot application, read the end of answer
Add following plugin to your pom.xml
The latest version can be found at
...
org.apache.maven.plugins
maven-assembly-plugin
CHOOSE LATEST VERSION HERE
jar-with-dependencies
assemble-all
package
single
...
After configuring this plug-in, running mvn package
will produce two jars: one containing just the project classes, and a second fat jar with all dependencies with the suffix "-jar-with-dependencies".
if you want correct classpath
setup at runtime then also add following plugin
org.apache.maven.plugins
maven-jar-plugin
true
fully.qualified.MainClass
For spring boot application use just following plugin (choose appropriate version of it)
org.springframework.boot
spring-boot-maven-plugin
true
${start-class}
repackage