Java RXTX 库不加载本机库 [英] Java RXTX Library doesn't load native library

查看:33
本文介绍了Java RXTX 库不加载本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想使用 RXTX 库为我的 Arduino 编写一个简单的通信工具 java 并且在加载动态库时失败了.

Basically i wanted to write a simple communication tool for my Arduino using the RXTX Library for java and failed horribly when it came to loading the dynamic library.

我的系统规格:
操作系统:OS X Yosemite 10.10.3
Java:SDK 1.8.0_45
RXTX: 2.1-7r2 - 运行 64 位 java 的 intel mac 的修改版本,可以在 此处.
IDE:NetBeans 8

My system specs:
OS: OS X Yosemite 10.10.3
Java: SDK 1.8.0_45
RXTX: 2.1-7r2 - modified version for intel mac running 64 bit java, which can be found here.
IDE: NetBeans 8

我检查了这些文件是否按照安装说明工作,这只是将这两个文件复制到/Library/Java/Extensions 目录中.

I checked, that these files work by following the install instructions, which is simply copying these two files into the /Library/Java/Extensions directory.

现在我想删除它们并从我的应用程序中加载库.我做了以下事情:

Now I wanted to remove them and load the library from my application. I did the following:

  • 将 RXTXcomm 库添加到 netbeans 中的项目.
  • 使用以下代码将本机库的容器包含在java.library.path"属性中

System.setProperty("java.library.path",location.getPath() + File.pathSeparator + System.getProperty("java.library.path"));

  • 并使用System.loadLibrary("rxtxSerial")
  • 加载库

当我编译代码并尝试运行它时,它给了我一个
java.lang.UnsatisfiedLinkError: java.library.path 中没有 rxtxSerial

When I compiled the code and tried to run it, it gave me an
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path

现在我想知道我做错了什么(也许是一些很大的误解?)

Now I'm wondering what i have done wrong (maybe some great misunderstanding?)

任何帮助将不胜感激!

推荐答案

除了我最近的回复 这个.

这是删除提到的缓存的代码:

This is the code to delete the mentioned cache:

try {
    Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
    fieldSysPath.setAccessible(true);
    fieldSysPath.set(null, null);
} catch (NoSuchFieldException |
        SecurityException |
        IllegalArgumentException |
        IllegalAccessException ex) {
    ex.printStackTrace(System.err);
}

所以问题不在于 rxtx 库,而在于我自己未能阅读 java 文档.因为我确定在开头的某个地方提到了这一点.

So the issue was not the rxtx library but rather my own failure to read the java doc. Because I'm sure this is mentioned somewhere right at the beginning.

这篇关于Java RXTX 库不加载本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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