nar-maven-plugin和native-library-loader不加载本地lib [英] nar-maven-plugin and native-library-loader dont load native lib

查看:100
本文介绍了nar-maven-plugin和native-library-loader不加载本地lib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用nar-maven-plugin进行测试,然后在下一个项目中我需要JNI :(.我选择了

I testing with nar-maven-plugin, then in the next project I need JNI :( . I choosed the it0003 example from git repo. Without the native-library-loader, manual placing of the library and setting of library path its run. Then i would use the native-library-loader. For that, I added the dependency and the assembly-plugin for single JAR file. My current pom:

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

然后,我将生成的JAR和NAR放在同一目录中,并开始于:

Then I placed the resulting JAR and the NAR in the same directory and starts with:

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

然后我得到以下错误:

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)

有人知道我的错误是什么吗?

Has anyone an idea what my mistake is?

推荐答案

遇到同样的问题.

确保已设置$ JAVA_HOME环境变量.在Linux上,您可以使用which java找到它,然后使用export <path>导出路径. 另外,您应该链接到pom.xml文件中编译器选项中的include路径:

Make sure your $JAVA_HOME environment variable is set. On Linux, you can find this using which java, then exporting the path using export <path>. Additionally, you should link to the include paths in the compiler options in your 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>

希望这会有所帮助,可以肯定的是它可以解决此问题.如果我弄清楚实际上是什么解决的,我将更新此答案.

Hopefully this helps, pretty sure this was what fixed it. If I figure out what actually fixed it, I'll update this answer.

这篇关于nar-maven-plugin和native-library-loader不加载本地lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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