Build jar with dll in pom or external dll file - unable to solve

38 Views Asked by At

I'm fighting with this issue for a few days already, so I'm really in need of your help, girls and boys.

I did a simple stuff in Java, that works till I'm using my IDE (IntelliJ) - I can run my program and it works beautifuly.

I have, among others, one dependency that in POM needs <type>dll</type> added, otherwise Maven says XYZ was not found in https://repo.maven.apache.org/maven2. The problem shows when I'm trying to build (install) a jar file, that is required to finish the task.

I had:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>
                                        Main
                                    </mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

and with that and <type>dll</type> on dependency added I got no such archiver 'dll'.

I tried with Project Structure -> Modules and Libraries, but still this is a solution for local/IDE running.

I tried few configurations with maven-jar-plugin and maven-dependency-plugin, yet still nothing.

My attempt to build an assembly:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

    <id>assembly-with-dll</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <!-- package the regular dependencies -->
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <unpack>true</unpack>
            <scope>runtime</scope>
            <!-- exclude the DLL -->
            <excludes>
                <exclude>*:dll*</exclude>
            </excludes>
        </dependencySet>
        <!-- package the DLLs -->
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*:dll*</include>
            </includes>
        </dependencySet>
    </dependencySets>
</assembly>

with changed maven-assembly-plugin

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/main/assembly/assembly.xml</descriptor>
                            </descriptors>
                            <archive>
                                <manifest>
                                    <mainClass>
                                        Main
                                    </mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I also tried to add troublesome dll file to /resources, then unpack it to jar's location and use System.load - both as file and stream - yet nothing.

I even tried to parse paths from java.library.path, find something from jre and/or bin, put file there and use System.loadLibrary - nothing.

Then put dll file by hand to one of java.library.path and use hardcoded System.loadLibrary - nothing.

From System.load and System.loadLibrary mentioned above I didn't get any exceptions or fauls.

After all this, I just put .jar file with dll file in one folder and run it with: java -Djava.library.path=QWERTY -jar XYZ.jar and it worked.

But it still bothers me. Isn't there any working solution to have everything under one runable jar file? Where is my fault?

0

There are 0 best solutions below