My unit tests work in eclipse because the path to the DLL is set properly in jna.library.path.
But mvn test which uses the plugin fails with this error.
Unable to load library 'ehlapi32': Native library (win32-x86-64/ehlapi32.dll) not found in resource path
<plugin><!-- This doesn't work -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<workingDirectory>target</workingDirectory>
<forkmode>never</forkmode>
<argLine>-Djna.library.path=C:/my.dll</argLine>
</configuration>
</plugin>
This is my surefire configuration that solved the problem. The particular DLL I was trying to load required a 32-bit JVM. So I specified that.
After this the DLL is found using one of the recommended approaches to load dll's using JNA.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<workingDirectory>target</workingDirectory>
<forkmode>once</forkmode>
<jvm>C:\Program Files (x86)\Java\jdk1.8.0_102\bin\java</jvm>
</configuration>
</plugin>