【问题标题】:maven-nar-plugin and tests in dependent modulemaven-nar-plugin 和依赖模块中的测试
【发布时间】:2013-12-04 10:01:37
【问题描述】:

我有两个 Maven 模块:

  1. native-wrapper - 是系统库的 JNI 包装器,由 nar-maven-plugin 构建。
  2. main-module - 依赖于 native-wrapper 并在测试期间使用它的 JNI 调用。

本机包装器中的测试工作正常。但是,在主模块中的测试期间,我得到“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>

如果我从主模块的 pom 中删除 nar-maven-plugin 插件,maven 不会从 native-wrapper 模块中找到任何类。

如何让 nar 找到库?

【问题讨论】:

    标签: java maven maven-nar-plugin


    【解决方案1】:

    看起来,不能只使用&lt;type&gt;nar&lt;/type&gt; 添加工件并运行测试。您应该自己为 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-06
      • 1970-01-01
      • 2010-12-16
      • 2010-10-22
      • 2017-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多