Xorty
Xorty

Reputation: 18861

maven-surefire-plugin, DLLs and java.library.path

I have a Maven dependency that requires a DLL at runtime. What I want to do is to simply have that dll in resources/lib folder and place its DLLs to the target directory. So what've I done is :

  1. Added DLLs to src/main/resources/lib
  2. Modified pom.xml to use argument -Djava.library.path=${basedir}/lib like so:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <forkMode>once</forkMode>
            <workingDirectory>target</workingDirectory>
            <argLine>-Djava.library.path=${basedir}/lib</argLine>
        </configuration>
    </plugin>
    

However I am still getting runtime error that DLL is not present in java.library.path.

Upvotes: 22

Views: 14272

Answers (1)

carlspring
carlspring

Reputation: 32627

Your <argLine/> points to an incorrect path. Try this instead:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <forkMode>once</forkMode>
        <workingDirectory>target</workingDirectory>
        <argLine>-Djava.library.path=${basedir}/src/main/resources/lib</argLine>
    </configuration>
</plugin>

If this DLL will only be used for tests, you should put it under src/test/resources. In that case the <argLine/> path will change to ${project.build.directory}/test-classes.

Upvotes: 18

Related Questions