tags:

views:

139

answers:

2

I have a project (of type 'jar') that (obviously) builds a jar. But that project has many dependencies. I'd like Maven to build a "package" or "assembly" that contains my jar, all the dependent jars, and some scripts (to launch the application, etc.)

What's the best way to go about this? Specifically, what's the best way to get the dependents into the assembly?

+1  A: 

I have used the maven assembly plugin to packages everything in one single jar. you can find info here http://maven.apache.org/plugins/maven-assembly-plugin/ http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

HTH.

Thillakan
+3  A: 

For a single module, I'd use an assembly looking like the following one (src/assembly/bin.xml):

<assembly>
  <id>bin</id>
  <formats>
    <format>tar.gz</format>
    <format>tar.bz2</format>
    <format>zip</format>
  </formats>
  <dependencySets>
    <dependencySet>
      <unpack>false</unpack>
      <scope>runtime</scope>
      <outputDirectory>lib</outputDirectory>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>src/main/command</directory>
      <outputDirectory>bin</outputDirectory>
      <includes>
        <include>*.sh</include>
        <include>*.bat</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>target</directory>
      <outputDirectory>lib</outputDirectory>
      <includes>
        <include>*.jar</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

To use this assembly, add the following configuration to your pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <descriptors>
        <descriptor>src/assembly/bin.xml</descriptor>
      </descriptors>
    </configuration>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

In this sample, start/stop scripts located under src/main/command and are bundled into bin, dependencies are bundled into lib. Customize it to suit your needs.

Pascal Thivent
I figured this was common enough to have warranted a built-in assembly..but apparently not. Thanks, as always.
Jared
I really agree, it would make sense to have a predefined descriptor for something like this (based on some conventions, e.g. scripts location).
Pascal Thivent