简体   繁体   中英

maven-nar-plugin and tests in dependent module

I have two maven modules:

  1. native-wrapper - is a JNI wrapper over system lib, that is build by nar-maven-plugin.
  2. main-module - depends on native-wrapper and uses it's JNI calls during tests.

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

native-wrapper's pom includes:

...
<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>

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".

main-module's 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>

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

How can I make nar find the lib?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM