I have a JNI project configured with Maven using the nar-maven-plugin
. Both the Java and the C++ code reside in the project. The main code apparently compiles properly (both C++ and Java). The problem is with the test code (JUnit).
The test code defined one Java class that itself has a native method. The corresponding native code resides in the directory
<project root>
+- src
+- test
+- c++
There is no evidence from the build messages that this native test code is ever compiled and the corresponding native method does not appear at all when I run nm
from the command line on the DLL created by the build process. In addition, I intentionally put a syntax error into the test code and recompiled to see if I would get a compile-time error. There is no error, consistent with my belief that the code is never compiled.
Correspondingly, I get an UnsatisfiedLinkError
when the test runs during mvn install
. Note that I can tell from the point at which the test failed that the native methods for the main (non-test) code were properly loaded and linked. Hence I conclude that there is some problem related to the building and linking of native test code specifically.
I'm currently on Windows 10 using the Eclipse IDE and MinGW compilers for native code.
The relevant sections of my POM are below (slightly updated from my answer on Avoiding machine-dependent POM with MinGW compiler and nar-maven-plugin related to an early configuration problem):
<profiles>
<profile>
<id>Windows-MinGW</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.5.1</version>
<extensions>true</extensions>
<configuration>
<cpp>
<options>
<option>-std=c++1y</option>
</options>
</cpp>
<linker>
<name>g++</name>
<options>
<option>-Wl,--kill-at</option>
</options>
</linker>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<defaultGoal>integration-test</defaultGoal>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.5.1</version>
<extensions>true</extensions>
<configuration>
<cpp>
<defines>
<define>EXPORT_DLL</define>
</defines>
</cpp>
<libraries>
<library>
<type>jni</type>
<narSystemPackage>com.mycompany.sandbox</narSystemPackage>
</library>
</libraries>
</configuration>
</plugin>
</plugins>
</build>
Is there a known way to handle this problem? (Maybe additional configuration tags?)