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

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

问题描述

基本上我想使用 RXTX库java写我的Arduino一个简单的通讯工具当它来加载动态库并没有可怕的。

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约塞米蒂10.10.3结果
Java的:SDK 1.8.0_45结果
RXTX:2.1-7r2 - 改良版Intel Mac上运行64位Java,它可以找到的此处。结果
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

我查了一下,这些文件按照安装说明,这简直就是将这两个文件复制到/图书馆/的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属性,使用下面的一段code的容器

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


  • 并采用加载库的System.loadLibrary(rxtxSerial)

  • And load the library using System.loadLibrary("rxtxSerial")

当我编译code,并试图运行它,它给了我一个
结果 java.lang.UnsatisfiedLinkError中:没有rxtxSerial中的java.library.path

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

任何帮助将是AP preciated!

Any help would be appreciated!

推荐答案

这一个解释,您的问题和建议解决办法。

This an explanations to your problem and a suggestion to a solution.

RXTX在我看来两个主要问题:

RXTX has two major problems in my opinion:


  1. 根据您的IDE,您需要将在Mac: RXTXcomm.jar librxtxSerial.jnilib PC: RXTXcomm.jar rxtxSerial.dll 对项目在IDE或Java code盘根,它变化从IDE到IDE。文档在这里不介绍如何做到在不同的IDE像NetBeans中的IntelliJ甚至因此我得到了它在Eclipse和工作的IntelliJ,但不是没有的NetBeans。我还有其他的问题。

  2. 根据您的操作系统,即使你得到这个包起来并运行,在Windows 8.1为例,它有问题,关闭端口。唯一的解决办法就是重新启动你的IDE /控制台,并重新连接。

  1. Depending on your IDE, you need to place the Mac: RXTXcomm.jar and librxtxSerial.jnilib PC: RXTXcomm.jar, rxtxSerial.dll on the root of the project in your IDE or Java code, it varies from IDE to IDE. The documentation here does not cover how to do it in different IDE like NetBeans, IntelliJ even thus I got it to work on both Eclipse and IntelliJ, but not NetBeans yet. I still have other issues.
  2. Depending on your OS, even if you get this package up and run, in Windows 8.1 as example, it has problem closing the port. And the only solution is to restart you IDE/console and reconnect.

无论如何,我建议你去那边更加封装问题少叫JSSC

Any way I suggest you going over to a more problem less package called JSSC

下面:

public class Main {

    public static void main(String[] args) {
        SerialPort serialPort = new SerialPort("COM1");
        try {
            serialPort.openPort();//Open serial port
            serialPort.setParams(9600, 8, 1, 0);//Set params.
            byte[] buffer = serialPort.readBytes(10);//Read 10 bytes from serial port
            serialPort.closePort();//Close serial port
        }
        catch (SerialPortException ex) {
            System.out.println(ex);
        }
    }
}


  • 请参见 JSSC 的所有例子codeS

  • 包可以下载这里

  • JSSC主页

    • See all examples of JSSC codes
    • The package can be downloaded here.
    • JSSC home page
    • 注意:这是一个开放式的答案,如果你的任何一个对本请编辑答案贡献经验。
      我看到有人问问题,并与RXTX我一般有几乎同样的问题。

      Note: This is an open answer, if any one of you have experience regarding this please contribute by editing the answer. I have seen people asking question and having almost same problem with RXTX I general.

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

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