Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven shade plugin Packaging DLL

Tags:

java

maven

dll

I have to add to my project a JNI module.

I install the module in Maven as two different artifact: the jar library:

mvn install:install-file -DgroupId=com.test -DartifactId=ssa -Dversion=1.0 -Dpackaging=jar -Dfile=ssa.jar

and the runtime library with the DLL

mvn install:install-file -DgroupId=com.sirio -Dpackaging=ddl -DartifactId=ssa-runtime -classifier=windows-x86 -Dversion=1.0 -Dfile=SSADll.dll

In my maven project I add these dependecies:

    <dependency>
        <groupId>com.test</groupId>
        <artifactId>ssa</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>com.test</groupId>
        <artifactId>ssa-runtime</artifactId>
        <classifier>windows-${arch}</classifier>
        <type>dll</type>
        <version>1.0</version>
        <scope>runtime</scope>
    </dependency>

My problem is when I run the shade plugin goal to create a jar with dependencies, I get error:

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project ....: Error creating shaded jar: error in opening zip file sirio\ssa-runtime\1.0\ssa-runtime-1.0-windows-x86.dll 

How can I tell the shade plugin to do not unpack the dll?

like image 330
Panciz Avatar asked Jun 03 '14 09:06

Panciz


People also ask

What is Maven Shade plugin for?

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

What is uber-jar maven?

An uber-JAR—also known as a fat JAR or JAR with dependencies—is a JAR file that contains not only a Java program, but embeds its dependencies as well. This means that the JAR functions as an “all-in-one” distribution of the software, without needing any other Java code.

How do you shade a dependency?

In Java, to “shade” a dependency is to include all its classes and the classes from its transitive dependencies in your project, often renaming the packages and rewriting all affected bytecode.

Why do we need shaded jar?

Shading is a process where a dependency is relocated to a different Java package and copied into the same JAR file as the code that relies on that dependency. The main purpose of shading is to avoid conflicts between the versions of dependencies used by a library and the versions used by the consumers of that library.


1 Answers

Maybe what you need is to package differently. Make the shaded jar with all java classes and libraries you use and then package this jar and the DLL together in a Zip file to be released. For this you can use the maven-assembly-plugin with a descriptor for your zip, like this:

In your pom.xml:

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptors>
                        <descriptor>zip.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

In zip.xml file:

    <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
        <id>release</id>
        <formats>
            <format>zip</format>
        </formats>
        <fileSets>
            <fileSet>
                <directory>target</directory>
                <includes>
                    <include>myapp.jar</include>
                </includes>
                <outputDirectory>/</outputDirectory>
            </fileSet>
        </fileSets>
        <files>
            <file>
                <source>your.dll</source>
                <fileMode>0644</fileMode>
            </file>
        </files>
    </assembly>

That way you have all you need to release in this zip. I don't know if that's the best solution, but maybe it solves the problem for your use case.

like image 194
itamarc Avatar answered Sep 27 '22 19:09

itamarc