Maven - Creating an executable jar

less than 1 minute read

I wanted to create an executable jar in maven , s.t whenever I run”mvn install” , it will generate both the regular one and the executable one.

all the data here is taken from this stackoverflow question and this maven example page.

In your pom.xml file , add this :


**Short explanation : **
The artifactId is the plugin name (no packageId is required , because it’s from the default maven package).
In the configuration we define the location of the main class , and which plugin we’re running
And then , the execution : that tells the plugin when to run. In this case , it will run in the packaging phase.

How to run
All you need to do is run

mvn install 

if you want only to create the executable jar , you can run

mvn assembly:assembly