nar-maven-plugin 和 native-library-loader 不加载本机库

2023-12-31

我使用 nar-maven-plugin 进行测试,然后在下一个项目中我需要 JNI :( 。我选择了it0003 https://github.com/maven-nar/nar-maven-plugin/tree/master/src/it/it0003-jni来自 git 存储库的示例。如果没有本机库加载器,则手动放置库并设置其运行的库路径。然后我会使用本机库加载器。为此,我添加了单个 JAR 文件的依赖项和程序集插件。我当前的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 放在同一目录中,并以以下内容开头:

    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)

有谁知道我的错误是什么?


遇到了同样的问题。

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

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

希望这会有所帮助,很确定这就是修复它的原因。如果我弄清楚到底是什么解决了这个问题,我会更新这个答案。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

nar-maven-plugin 和 native-library-loader 不加载本机库 的相关文章

  • 如何在 Spring MVC 中使用延迟加载

    Spring MVC中如何使用延迟加载 我现在正在使用 eager 但这会使我的应用程序运行速度变慢 这是我的域的一部分 ManyToMany fetch FetchType EAGER JoinTable name NEWS TAG jo
  • 具有替代方案的重载方法值表

    我有编译器抱怨的以下代码 val state KTable String String builder table BARY PATH Materialized as PATH STORE 错误信息 error home developer
  • 如何阻止 Apache CXF 发送响应消息?

    如果给定的 SOAP 标头元素具有给定值 例如 如果标头标记 response 的值为 0 我根本不希望 Apache CXF 返回响应 我怎样才能做到这一点 CXF 似乎假设所有呼叫都会收到响应 我知道这在 Web 服务上下文中看起来很奇
  • Apache Poi 无法读取工作表名称

    我们在通过 Apache Poi 读取 Excel 工作表时遇到了一个奇怪的错误 我们使用的是5 0版本 该代码以前可以工作 但现在已停止在我们所有的生产环境中工作 它在本地测试时仍然有效 因此事实证明这很难调试 问题是我们返回了空工作表名
  • 将密钥添加到选定的密钥集中

    我正在编写一个 NIO 服务器 并希望响应用户请求 即将一些数据写入通道 Selector selector if selector selectNow 0 if key isReadable SocketChannel channel k
  • 我应该使用 Facelets“jsfc”属性吗?

    Facelets 使用jsfc属性将 HTML 元素转换为其关联的JSF成分 这对于快速原型设计非常有帮助 因为它允许您使用可视化设计工具创建视图 然而我最近发现this http weblogs java net blog 2008 12
  • Java 文档生成器为 Xml 字符串返回 null 文档

    I have tried all possible answers https stackoverflow com questions 33098082 passing xml string as document returning nu
  • 根据使用频率随机生成字母?

    如何根据常用语音中的使用频率随机生成字母 任何伪代码都值得赞赏 但如果用 Java 实现就更棒了 否则 只需朝正确的方向戳一下就会有所帮助 注意 我不需要生成使用频率 我确信我可以很容易地查找到它 我假设您将频率存储为 0 到 1 之间的浮
  • 如何处理过时的连接?

    我们的应用程序是一个 J2EE 应用程序 在 Websphere 6 1 上通过 Mainframe DB2 后端使用 Struts EJB Hibernate 最近已投入生产 我们收到过时的连接异常当用户第一次或有时登录应用程序时 此异常
  • 如何编译telegram jni文件夹

    我正在尝试编译电报源代码中的 jni 文件夹github com DrKLO Telegram http github com DrKLO Telegram 与NDK 但是当我在 ndk 文件夹中的 cmd 中编写 ndk build 时
  • 将 AOP 与 OSGI 结合使用的最佳解决方案?

    我正在使用 Equinox 因此 Equinox Aspect 项目似乎是理所当然的 但该项目似乎处于非活动状态 并且只有一页文档 让我最终悬而未决 除了那个项目之外 我没有看到在 OSGI 中使用 AOP 的很多选项 让我知道你们的想法以
  • 使用 google app-engine 跨浏览器/服务器重新启动会话持久性

    如何使会话在浏览器 服务器重新启动后持续存在 我正在使用谷歌应用程序引擎 每次重新启动浏览器和 或服务器时 我都会得到一个新的会话 ID String jSessionId this getThreadLocalRequest getSes
  • Dao 和服务接口的需求

    我是Spring Mvc的新手 在很多教程中 我发现有一个像这样的Dao接口 public interface StudentDAO public List
  • Java中使用流的byte[]到byte[]的ArrayList

    我有一个 byte 的 ArrayList 我想知道是否可以使用 Java 8 中的流将其转换为 byte ArrayList 内的所有数组都具有相同的大小 ArrayList
  • jni.h:没有这样的文件或目录

    我一直在关注本教程 http www java tips org other api tips jni simple example of using the java native interface html 在第 5 步 我从 GCC
  • 编写无 BOM 的 UTF-8

    这段代码 OutputStream out new FileOutputStream new File C file test txt out write A getBytes 和这个 OutputStream out new FileOu
  • 在 Apache POI 4.0 中为 XSSFWorkbook 创建自定义颜色样式

    要在 Apache POI 3 7 及更低版本中为 XSSFWorkbook 应用自定义颜色 可以执行以下操作 java awt Color c new java awt Color 1 2 3 XSSFCellStyle xcs xssf
  • Java 泛型和数字

    为了看看我是否可以清理一些数学代码 主要是矩阵代码 我尝试使用一些 Java 泛型 我有以下方法 private
  • 为什么不建议将常量存储在单独的类中?

    有人告诉我 我在其他一些地方也看到过这种说法 不建议将常量存储在 Java 中的单独类中 以便在其他类中使用它们 但我没有看到任何地方为什么会这样 我不应该将它们存储在自己的接口 类中的原因是什么 我从 C 转到 Java 在 C 中我只想
  • Maven:找不到处理 Castor、antrun 和 Ear 插件的市场条目

    我正在将 Maven 项目导入到 Eclipse 中 我安装了 m2e 插件 它指向我的机器上的 maven 2 2 1 我收到这三个错误 在 Eclipse 中找不到处理 Castor maven plugin 1 0 generate

随机推荐