Maven-nar-plugin和相关模块中的测试 [英] maven-nar-plugin and tests in dependent module

查看:126
本文介绍了Maven-nar-plugin和相关模块中的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Maven模块:

I have two maven modules:

  1. native-wrapper-是由nar-maven-plugin构建的系统lib的JNI包装器.
  2. 主模块-依赖于本地包装器,并在测试期间使用其JNI调用.

在本地包装程序中的测试工作正常.但是,在主模块中进行测试时,出现"UnsatisfiedLinkError"- NarSystem无法找到我的JNI库.

Tests in native-wrapper work fine. But, during tests in main-module, I get "UnsatisfiedLinkError" - NarSystem is unable to locate my JNI lib.

本地包装程序的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".

I opened generated .nar in ./target/ - it does contain "/lib/amd64-Linux-gpp/jni/libnative-wrapper-0.1.0-SNAPSHOT.so". The other nar (with java classes) contains "/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模块中找到任何类.

If I remove nar-maven-plugin plugin from main-module's pom, maven does not find any classes from native-wrapper module.

如何使nar找到库?

推荐答案

似乎,不能只用<type>nar</type>添加工件并运行测试.您应该自己为Java设置正确的库路径.我是这样做的(除了主模块的pom之外):

It seems like, one can't just add artifact with <type>nar</type> and run tests. You should set proper library path for java yourself. I did it like this (in addition to main-module's 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>

这篇关于Maven-nar-plugin和相关模块中的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆