11

I have a mavenized java project (Maven2) which I want to build into a jar, which is easy enough by supplying the jar-with-dependencies descriptorRef in the pom.xml.

However I also need to deploy my project in a zip with some .exe and .bat files, among others, from a bin folder that call the jar. (I am using Tanuki but it does not matter for the use case I think)

In other words, I need a build in which first my sources (and dependencies) are packaged into a jar and that jar is then put into a zip with some additional files from the bin folder.

What should I put in my pom.xml and 'assembly'.xml?

NomeN
  • 17,140
  • 7
  • 32
  • 33

1 Answers1

12

Maven-assembly-plugin is the right tool to do that.

You have to declare this plugin in the "build" section of your pom, and to create another configuration file "assembly.xml" at the root of your project. In this file, your will define the content of your zip file.

The configuration options are described on the official site: http://maven.apache.org/plugins/maven-assembly-plugin/

Here is a basic configuration example of this plugin that should suit your needs.

POM config :

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <finalName>zipfile</finalName>
        <descriptors>
            <descriptor>${basedir}/assembly.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Assembly config :

<assembly>
    <formats>
        <format>zip</format>
    </formats>

    <fileSets>
        <fileSet>
            <directory>to_complete</directory>
            <outputDirectory />
            <includes>
                <include>**/*.jar</include>
                <include>**/*.bat</include>
                <include>**/*.exe</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>
Benoit Courtine
  • 7,014
  • 31
  • 42
  • Thanks for your answer, it was the crucial kick start I needed to get it working. – NomeN Feb 09 '11 at 15:45
  • 3
    I did need to add another descriptor that makes my jar though. Actually I just copied the jar-with-dependencies descriptor format from the site you mentioned, as using the jar-with-dependencies descriptorRef enveloped the zip build. i.e. it builds the 'sic' jar first then the zip and then the with-dependencies.jar, which builds a zip with the first (useless) jar but without the second, weird right?! – NomeN Feb 09 '11 at 15:54