我有两个maven模块:
在native-wrapper中进行测试工作正常。但是,在主模块测试期间,我得到“UnsatisfiedLinkError” - NarSystem无法找到我的JNI库。
native-wrapper的pom包括:
...
<packaging>nar</packaging>
...
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.0.0-rc-2</version>
<extensions>true</extensions>
<configuration>
<libraries>
<library>
<type>jni</type>
<narSystemPackage>some.native.wrapper</narSystemPackage>
</library>
</libraries>
</configuration>
</plugin>
我在./target/中打开生成的.nar - 它确实包含“/lib/amd64-Linux-gpp/jni/libnative-wrapper-0.1.0-SNAPSHOT.so”。另一个nar(使用java类)包含“/META-INF/nar/some.native.wrapper/native-wrapper/nar.properties”。
主要模块的pom:
...
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>native-wrapper</artifactId>
<version>${project.version}</version>
<type>nar</type>
</dependency>
...
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.0.0-rc-2</version>
<extensions>true</extensions>
</plugin>
如果我从main-module的pom中删除了nar-maven-plugin插件,maven就找不到native-wrapper模块中的任何类。
如何让nar找到lib?
答案 0 :(得分:1)
看起来,人们不能只用<type>nar</type>
添加工件并运行测试。您应该自己为java设置适当的库路径。我是这样做的(除了主模块的pom):
<packaging>nar</packaging>
...
<properties>
<LIBRARY_PATH>${project.build.directory}/nar/native-wrapper-${project.version}-amd64-Linux-gpp-jni/lib/amd64-Linux-gpp/jni/:${project.build.directory}</LIBRARY_PATH>
</properties>
...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<environmentVariables>
<LD_LIBRARY_PATH>${LIBRARY_PATH}</LD_LIBRARY_PATH>
<DYLD_LIBRARY_PATH>${LIBRARY_PATH}</DYLD_LIBRARY_PATH>
</environmentVariables>
<systemProperties>
<property>
<name>java.library.tmpdir</name>
<value>${LIBRARY_PATH}</value>
</property>
<property>
<name>java.library.path</name>
<value>${LIBRARY_PATH}</value>
</property>
</systemProperties>
...
</plugin>