Search code examples
javamavenmaven-assembly-plugin

Unzip a file located on disk (maven-assembly-plugin)


I'm trying to output all the files required to run a project in a ./target/dist folder. I'd like to bundle a JRE while preparing the assembly. The JRE is located at the base directory of my project and is contained in a zip file called jre.zip.

How can ./jre.zip be unpacked in the ./target/dist folder?

Here's the XML for my assembly.

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>dist</id>
    <formats>
        <format>dir</format>
    </formats>
    <baseDirectory>./</baseDirectory>
    <fileSets>
        <fileSet>
            <directory>./</directory>
            <outputDirectory>./jre</outputDirectory>
            <excludes>
                <exclude>*/**</exclude>
            </excludes>
        </fileSet>
    </fileSets>
    <files>
        <file>
            <source>${project.build.directory}/${project.build.finalName}.jar</source>
            <destName>${artifactId}.jar</destName>
            <outputDirectory>./</outputDirectory>
        </file>     
    </files>
</assembly>

Solution

  • While you can unpack dependencies with the Maven Assembly Plugin, I'm pretty sure that won't work with the jre...

    I suggest you unpack the jre before executing the Assembly plugin like so

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.6</version>
        <executions>
            <execution>
                <id>prepare</id>
                <phase>validate</phase>
                <configuration>
                    <tasks>
                        <echo message="prepare phase" />
                        <unzip src="jre.zip" dest="target/jre"/>
                    </tasks>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>