Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

building a jar and including it in a zip with maven-assembly-plugin

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?

like image 287
NomeN Avatar asked Feb 09 '11 12:02

NomeN


1 Answers

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>
like image 50
Benoit Courtine Avatar answered Oct 07 '22 18:10

Benoit Courtine