'Mavenproject: how to depend on a .jar with accompanying .dll

I have a small Java project that requires a third party .jar with an accompanying .dll and I can't get the project to find the .dll. The jar file is added normally via an installed dependency, which works fine.

    <dependency>
        <groupId>com.company</groupId>
        <artifactId>companyJar</artifactId>
        <version>1.20</version>
    </dependency>

I had tried different approaches. The first one, installing the dll

mvn install:install-file -Dfile=thirdParty.dll -DgroupId=com.company -DartifactId=companyDll  -Dversion=1.20 -Dpackaging=dll -DgeneratePom=true

and adding the dependency:

<dependency>
    <groupId>com.company</groupId>
    <artifactId>companyDll</artifactId>
    <version>1.20</version>
    <scope>runtime</scope>
    <type>dll</type>
</dependency>

This didn't work. Second attempt was removing the dependency to the dll and placing it in src/main/resources. The .dll is now placed correctly in the base of the resulting .jar, but the java.library.path is not correct, and I get a java.lang.UnsatisfiedLinkError on runtime.

I tried extending the java.library.path via the maven-surefire-plugin with different variants / combinations of the out commented values in the following snippet:

        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
          <configuration>
            <systemPropertyVariables>
              <property>
                <name>java.library.path</name>
                  <value>${project.build.directory}</value>
                <!-- <value>${basedir}/src/main/resources</value> -->
              </property>
            </systemPropertyVariables>
            <!-- <forkMode>once</forkMode> -->
            <!-- <workingDirectory>target</workingDirectory> -->
            <argLine>-Djava.library.path=${basedir}/src/main/resources</argLine>
            <!-- <argLine>-Djava.library.path=${basedir}/src/main/resources:${java.library.path}</argLine> -->
          </configuration>
        </plugin>

According to the text in the java.lang.UnsatisfiedLinkError message, it seems like the java.library.path is not altered by any of those maven-surefire-plugin entries (or it is truncated in the error message).

So - what am I doing wrong here? What would be the correct way to tell maven/java that the .dll can be found in the root of the resulting .jar?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source