Skip to content
Agustin Muñoz edited this page Jul 27, 2015 · 16 revisions

##How to use EasyPack Maven Plugin

As the new packaging types are not part of the Maven distribution, it is required to add a reference to the plugin in the pom file.

          <plugin>
               <groupId>com.github.easypack</groupId>
               <artifactId>easypack-maven-plugin</artifactId>
               <version>1.0</version>
               <extensions>true</extensions>
          </plugin>

Then, by setting the packaging to one of three jtar, jzip or jtargz the project is ready to be built.

The application layout

The final artifact will have the following layout:

{project.build.finalName}
       |
       |_ libs : the application's jars
       |
       |_ bin: the appliation scripts 

The main class

By default, the plugin configures the application for using ${project.groupId}.start.Start as the main class. If that class exists, then the start script can be executed and the application will start. Otherwise, the main class must be explicitly configured (see Configuration section)

The start script

The plugin creates a start script that executes the java command in the following way:

java $JAVA_OPTS -jar libs/{project.build.finalName}.jar $JAVA_ARGS

It uses environmental variables so it can be configured after the application is distributed, but both variables can also be configured at build time (see Configuration section).

The bin folder

If the project has a bin folder under src/main/resources, all its content will be included in the final artifact bin folder. It is suppose to hold any script, besides the start, that needs to be distributed with the application.

Configuration

Property Value
opts Java Virtual Machine options (-Xmx, -Xms, etc,) and System properties (specified with -D) included in the start srcript.
args Arguments passed to the main method.
platforms Comma separated list of platforms the start script must be created for. Possible values: linux, windows. Default: linux
echo Which part of the start script is 'echoed' when executed. Possible values: all (echoes the whole script) or java (echoes only the java line). Default: no echo is perfomed.
mainClass The application main class. Default: ${project.groupId}.start.Start
includes A list of files or folders to be included in the final artifact, at the application root folder.
start.linux Name of the script to be executed before the start script for linux platform. It is merged in the final start script. Default: src/main/resources/bin/start-linux
start.windows Name of the script to be executed before the start script for Windows platform. It is merged in the final start script. Default: src/main/resources/bin/start-windows
jar.includes Files or folders to be included in the project jar.
jar.excludes Files or folder to be excluded from the project jar.

A full XML example

Here is an XML example using all the possible properties at the same time (not realistic).

<plugin>
     <groupId>con.github.easypack</groupId>
     <artifactId>easypack-maven-plugin</artifactId>
     <version>1.0</version>
     <extensions>true</extensions>
     <configuration>
       <opts>-Xmx3G -Xms512m -Denvironment=prod</opts>
       <args>hello application</args>
       <platforms>linux, windows</platforms>
       <mainClass>org.myapp.App</mainClass>
       <bin>
          <folder>/more-scripts/</folder>
       </bin>
       <start>
          <linux>src/main/resources/scripts/execute-before-start</linux>
       </start>
       <echo>all</echo>
       <includes>
          <folder>src/main/resources/conf</folder>
          <folder>src/main/resources/docs</folder>
       </includes>
       <jar>
         <excludes>/conf/, /docs/</excludes>
       </jar>
     </configuration>
</plugin>