Maven Assembly Plugin Example

The maven assembly plugin can be used to create the various jboss packaging types. This is useful for example if you have a complex configuration, or if multiple sar, har, or par artifacts should be created for a single build. The assembly plugin should be configured with the jboss packaging plugin as a dependency. This allows the assembly plugin to correctly handle the "sar" and other jboss formats.

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-4</version>
        <executions>
          <execution>
            <id>my-sar</id>
            <goals>
              <goal>single</goal>
            </goals>
            <phase>package</phase>
              <configuration>
                <descriptors>
                  <descriptor>src/assembly/my-sar.xml</descriptor>
                </descriptors>
              </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jboss-packaging-maven-plugin</artifactId>
            <version>2.1.1</version>
          </dependency>
        </dependencies>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

The assembly descriptor can then be configured with the "sar" format, as shown in the following example.

<assembly>
  <id>my-sar</id>
  <formats>
    <format>sar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>target/classes</directory>
      <outputDirectory>/</outputDirectory>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <outputFileNameMapping>${artifact.artifactId}.jar</outputFileNameMapping>
      <outputDirectory>/lib</outputDirectory>
    </dependencySet>
  </dependencySets>
</assembly>