Simple example

Configuring

The following is a basic configuration of the plugin, and an example of usage based on a project generated with:

mvn archetype:generate \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DgroupId=com.mycompany.app \
  -DartifactId=my-app \
  -Dversion=1.0-SNAPSHOT

Configuring the plugin in pom.xml:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>appassembler-maven-plugin</artifactId>
        <version>1.10</version>
        <configuration>
          <programs>
            <program>
              <mainClass>com.mycompany.app.App</mainClass>
              <id>app</id>
            </program>
          </programs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Using the generated scripts

$ mvn package appassembler:assemble
...
$ sh target/appassembler/bin/app
Hello World!
  • All dependencies and the artifact itself are placed in the defined assemble directory (defaults to $project.build.directory/appassembler).
  • A bin/ directory is created in the assemble directory and the generated bin scripts are placed in that directory (defaults to both unix shell scripts and Windows bat files).

Advanced example

The following is a configuration example with more of the available options set.

Configuring

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>appassembler-maven-plugin</artifactId>
        <version>1.10</version>
        <configuration>
          <!-- Set the target configuration directory to be used in the bin scripts -->
          <configurationDirectory>conf</configurationDirectory>
          <!-- Copy the contents from "/src/main/config" to the target
               configuration directory in the assembled application -->
          <copyConfigurationDirectory>true</copyConfigurationDirectory>
          <!-- Include the target configuration directory in the beginning of
               the classpath declaration in the bin scripts -->
          <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
          <!-- set alternative assemble directory -->
          <assembleDirectory>${project.build.directory}/mycompany-assemble</assembleDirectory>
          <!-- Extra JVM arguments that will be included in the bin scripts -->
          <extraJvmArguments>-Xms128m</extraJvmArguments>
          <!-- Generate bin scripts for windows and unix pr default -->
          <platforms>
            <platform>windows</platform>
            <platform>unix</platform>
          </platforms>
          <programs>
            <program>
              <mainClass>com.mycompany.app.WindowsApp1</mainClass>
              <id>app1</id>
              <!-- Only generate windows bat script for this application -->
              <platforms>
                <platform>windows</platform>
              </platforms>
            </program>
            <program>
              <mainClass>com.mycompany.app.UnixApp2</mainClass>
              <id>app2</id>
              <!-- Only generate unix shell script for this application -->
              <platforms>
                <platform>unix</platform>
              </platforms>
            </program>
            <program>
              <mainClass>com.mycompany.app.App3</mainClass>
              <commandLineArguments>
                <!-- Add two predefined command line arguments to the call of App3 -->
                <commandLineArgument>arg1</commandLineArgument>
                <commandLineArgument>arg2</commandLineArgument>
              </commandLineArguments>
              <id>app3</id>
            </program>
            <program>
              <mainClass>com.mycompany.app.App4</mainClass>
              <id>app4</id>
            </program>
          </programs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Using the generated scripts

$ mvn package appassembler:assemble
...
$ sh target/mycompany-assemble/bin/mycompanyapp2
Hello World!