Wednesday, May 12, 2010

How to Copy Dependencies and Automatically Add the Classpath into Manifest File

One thing that I like from NetBeans project for desktop applications is that it can include all the dependencies in dist/lib and include those dependencies in the MANIFEST.MF's classpath, so that we can just do java -jar or double click on the JAR. As a Maven user, I can achieve similar objective by adding few lines in my pom.xml.


The maven-dependency plugin is used to copy the dependencies in the target/lib. The maven-jar-plugin is used to create a MANIFEST.MF file and automatically add the classpath as well as mainClass. You need to make sure that an empty MANIFEST.MF is present in the src/main/resources/META-INF.


  1. Typo in org.apache.maven.plugins

    Should be:

    Thanks for the info.


  2. This comment has been removed by the author.