Looking for a JavaEE Architect or Potential Tech Co-Founder?
Please don't hesitate to contact me.

How to package a java standalone app using maven assembly

The sample codes below will assemble a zipped package of a java standalone app.

  • maven-jar-plugin - to create the jar
  • maven-assembly-plugin - to assemble the distribution package


What we have in the code:
  1. In the jar plugin we define the main class and set the classpath to lib.
  2. We supply a descriptor on how we want to assemble the distribution package. We also bind the plugin to maven's package phase and single goal. So that we we execute maven install, the package will be automatically generated.
assembly.xml file
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
 xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
 <id>MyApp Scraper</id>

assembly is an xml file where we define how we want to package our distribution. What we have:

  1. format of the package is zip
  2. We package all the resources inside src/main/resources folder excluding assembly.xml
  3. We include all the jar files in the ${project.build.directory} folder which is basically the target.
  4. We save the maven dependencies in the lib folder. Note that we set the class path to the same directory. We set transitive dependencies to true and includes all. For some reason, without include=*, some transitive dependencies are not included.
How to package a java standalone app using maven assembly How to package a java standalone app using maven assembly Reviewed by Edward Legaspi on Monday, December 26, 2016 Rating: 5

No comments:

Powered by Blogger.