Nar-maven-plugin and native-library-loader don't load native lib

I am testing with nar-maven-plugin, then in next project I need JNI :( I selected it0003 example from git repo. Without loader on native library, manual library placement and setting library path starts. Then I will use loader based on native library. For this I added dependency and assembly-plugin for one JAR file. My current pom is:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  #%L
  Native ARchive plugin for Maven
  %%
  Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.github.maven-nar.its.nar</groupId>
    <artifactId>it-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../it-parent/pom.xml</relativePath>
  </parent>

  <artifactId>it0003-jni</artifactId>
  <packaging>nar</packaging>

  <name>NAR JNI Test</name>
  <version>1.0-SNAPSHOT</version>
  <description>
    Simple JNI Library
  </description>
  <url>http://maven.apache.org/</url>

  <properties>
    <skipTests>true</skipTests>
  </properties>  

  <build>
    <defaultGoal>install</defaultGoal>
    <plugins>
      <plugin>
        <groupId>com.github.maven-nar</groupId>
        <artifactId>nar-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <cpp>
            <debug>true</debug>
          </cpp>
          <c>
            <testOptions>
              <testOption>-DTESTOPT="this is a nar-testCompile flag"</testOption>
            </testOptions>
          </c>
          <libraries>
            <library>
              <type>jni</type>
              <narSystemPackage>it0003</narSystemPackage>
              <linkCPP>false</linkCPP>
            </library>
          </libraries>
          <javah>
            <includes>
              <include></include>
            </includes>
          </javah>
          <tests>
            <test>
              <name>HelloWorld</name>
            </test>
          </tests>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4.1</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>it0003.HelloWorldJNI</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
      <dependency>
          <groupId>org.scijava</groupId>
          <artifactId>native-lib-loader</artifactId>
          <version>2.0.2</version>
      </dependency>
  </dependencies>
</project>

      

Then I put the resulting JAR and NAR in the same directory and started with:

    rd4@PC222-VirtualBox ~/Schreibtisch/nartest $ java -Djava.library.path=/home/rd4/Schreibtisch/nartest/ -jar it0003-jni-1.0-SNAPSHOT-jar-with-dependencies.jar 

      

Then I get the following error:

java.lang.RuntimeException: Library 'libit0003-jni-1.0-SNAPSHOT.so' not found!
    at it0003.NarSystem.getLibPath(NarSystem.java:141)
    at it0003.NarSystem.loadLibrary(NarSystem.java:45)
    at it0003.HelloWorldJNI.<clinit>(HelloWorldJNI.java:27)
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Library 'libit0003-jni-1.0-SNAPSHOT.so' not found!
    at it0003.NarSystem.getLibPath(NarSystem.java:141)
    at it0003.NarSystem.loadLibrary(NarSystem.java:45)
    at it0003.HelloWorldJNI.<clinit>(HelloWorldJNI.java:27)

      

Does anyone know what my mistake is?

+3


source to share


1 answer


Enter the same problem.

Make sure the $ JAVA_HOME environment variable is set. On Linux, you can find this with which java

and then export the path using export <path>

. Also, you must reference the include paths in the compiler options in the pom.xml file:



<c>
  <name>gcc</name>
  <exceptions>false</exceptions>
  <debug>false</debug>
  <includes>
    <include>**/*.c</include>
  </includes>
  <options>
    <option>-I${java.home}/include</option>
    <option>-I${java.home}/include/linux</option>
  </options>
</c>

<linker>
  <name>gcc</name>
  <options>
    <option>-I${java.home}/include</option>
    <option>-I${java.home}/include/linux</option>
  </options>
</linker>

      

Hope this helps, pretty sure this has been fixed. If I figure out what actually fixed, I'll update this answer.

0


source







All Articles