This article explains very shortly how to create a simple executable jar file using maven2.
First step is to create a new maven project:
Before importing the project into Eclipse we run following command inside the newly created myproject folder:
Now import the project into eclipse and open the pom.xml which will look like
Also the maven archetype already created a App.java whose main method prints "Hello World".
So now it's matter of defining in our manifest that we want to execute the main method of this java class.
First add a new source folder "src/main/resources". Inside this folder create a new folder "META-INF". Inside the META-INF folder create an empty file "MANIFEST.MF".
Make following changes to the pom.xml like below:
Now we can package our jar file from the command line:
Now go into the target folder where you will see the newly created myproject-1.0-SNAPSHOT.jar.
From the command line issue following command:
This will output Hello World! to the console.
However, keep in mind that when your project depends on multiple 3rd party jars, you definitely should take a look at
- maven-assembly-plugin
- maven-shade-plugin
Thank you very much!
ReplyDeleteThis short tutorial saved me a lot of time.
Thank you indeed!
very very helpful..
ReplyDeletethanks a lot.