1

I have 2 .zip files: shared-lib-windows.zip and shared-lib-linux.zip. A maven dependency jar looks for the the shared-lib directory under WEB-INF/lib/ and expects .exe or .out file to be present in the shared-lib directory.

How do I setup the .zip files in my pom.xml so that the appropriate zip file is picked up, extracted to the renamed(shared-lib, without the -os) directory?

I have already setup the maven dependency (jar) as:

    <profiles>
        <profile>
            <id>Linux</id>
            <dependencies>
                <dependency>
                    <groupId>com.dependency</groupId>
                    <artifactId>depedency-linux</artifactId>
                    <version>0.0.9</version>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>Windows</id>
            <dependencies>
                <dependency>
                    <groupId>com.dependency</groupId>
                    <artifactId>dependency-windows</artifactId>
                    <version>0.0.9</version>
                </dependency>
            </dependencies>
        </profile>
    </profiles>

Now I just want Maven to pick up the .zip files from either src/main/resources or .m2/.../ and do the magic!

I have looked into answers which suggested maven-ant-plugin, but someone mentioned that'd be uncool.

[edit: add info] I have a Maven web-project packaged as a .war and deployed to Tomcat. Also, the .exe/.out files are a 3rd party dependency with a size of 120/150 MB respectively. Since my git does not have large file support and the binaries won't be updated, I've zipped it and added to my Git managed Maven web-project.

sprkv5
  • 157
  • 1
  • 8

1 Answers1

0

I went through official documentation about Maven profiles, phases and properties. I came up with a solution that uses maven-antrun-plugin. I'm still looking for a solution that does not rely on it.

Run the below pom.xml on Linux with: mvn package -P Linux

<profiles>
    <profile>
        <id>Linux</id>
        <properties>
            <binary.zip>${project.basedir}/src/main/resources/binary-linux.zip</binary.zip>
            <unzip.folder>${project.build.directory}/${project.build.finalName}/WEB-INF/lib/binary</unzip.folder>
        </properties>
        <dependencies>
            <dependency>
                <groupId>com.dependency</groupId>
                <artifactId>depedency-linux</artifactId>
                <version>0.0.9</version>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>Windows</id>
        <properties>
            <binary.zip>${project.basedir}/src/main/resources/binary-windows.zip</binary.zip>
            <unzip.folder>${project.build.directory}/${project.build.finalName}/WEB-INF/lib/binary</unzip.folder>
        </properties>
        <dependencies>
            <dependency>
                <groupId>com.dependency</groupId>
                <artifactId>dependency-windows</artifactId>
                <version>0.0.9</version>
            </dependency>
        </dependencies>
    </profile>
</profiles>
...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>unzip-binary</id>
            <phase>prepare-package</phase>
            <configuration>
                <tasks>
                    <echo message="unzip the binary" />
                    <unzip src="${binary.zip}" dest="${unzip.folder}" />
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

This will extract the .zip into the ..WEB-INF/lib/binary directory (in the prepare-package phase) before archiving it into a .war (in the package phase) with maven-war-plugin plugin.

sprkv5
  • 157
  • 1
  • 8