无法在Mac OS上运行rxtx

Wil*_*ill 1 java rxtx

我正在尝试在Mac上使用rxtx JAR文件for Java(OSX 10.8).我已经安装RXTXcomm.jarlibrxtxSerial.jnilib,附带的.so文件/Library/Java/Extensions.我正在尝试执行示例代码:http: //arduino.cc/playground/Interfacing/Java

但我显然错过了一些东西,因为我得到了一堆cannot find symbol错误信息.

这是一对夫妇:

SerialTest.java:3: cannot find symbol
symbol  : class CommPortIdentifier
location: package gnu.io
import gnu.io.CommPortIdentifier;
             ^
SerialTest.java:4: cannot find symbol
symbol  : class SerialPort
location: package gnu.io
import gnu.io.SerialPort;
Run Code Online (Sandbox Code Playgroud)

在我的机器上安装的Java中是否有更基本的东西?我刚刚安装了Xcode 4.5,所以我认为一切都是为了运行这个简单的代码.

人们要求我将库放在同一目录中.附上一个lsjavac我正在运行的命令:

$javac -classpath RXTXcomm.jar:. SerialTest.java 

SerialTest.java:3: cannot find symbol
symbol  : class CommPortIdentifier
location: package gnu.io
import gnu.io.CommPortIdentifier;
             ^
SerialTest.java:4: cannot find symbol
symbol  : class SerialPort
location: package gnu.io
import gnu.io.SerialPort;
             ^
SerialTest.java:5: cannot find symbol
symbol  : class SerialPortEvent
location: package gnu.io
import gnu.io.SerialPortEvent; 
             ^
SerialTest.java:6: cannot find symbol
symbol  : class SerialPortEventListener
location: package gnu.io
import gnu.io.SerialPortEventListener; 
             ^
SerialTest.java:9: cannot find symbol
symbol: class SerialPortEventListener
public class SerialTest implements SerialPortEventListener {
                                   ^
SerialTest.java:10: cannot find symbol
symbol  : class SerialPort
location: class SerialTest
    SerialPort serialPort;
    ^
SerialTest.java:83: cannot find symbol
symbol  : class SerialPortEvent
location: class SerialTest
    public synchronized void serialEvent(SerialPortEvent oEvent) {
                                         ^
SerialTest.java:27: cannot find symbol
symbol  : class CommPortIdentifier
location: class SerialTest
        CommPortIdentifier portId = null;
        ^
SerialTest.java:28: cannot find symbol
symbol  : variable CommPortIdentifier
location: class SerialTest
        Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
                               ^
SerialTest.java:32: cannot find symbol
symbol  : class CommPortIdentifier
location: class SerialTest
            CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
            ^
SerialTest.java:32: cannot find symbol
symbol  : class CommPortIdentifier
location: class SerialTest
            CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
                                             ^
SerialTest.java:48: cannot find symbol
symbol  : class SerialPort
location: class SerialTest
            serialPort = (SerialPort) portId.open(this.getClass().getName(),
                          ^
SerialTest.java:53: cannot find symbol
symbol  : variable SerialPort
location: class SerialTest
                    SerialPort.DATABITS_8,
                    ^
SerialTest.java:54: cannot find symbol
symbol  : variable SerialPort
location: class SerialTest
                    SerialPort.STOPBITS_1,
                    ^
SerialTest.java:55: cannot find symbol
symbol  : variable SerialPort
location: class SerialTest
                    SerialPort.PARITY_NONE);
                    ^
SerialTest.java:84: cannot find symbol
symbol  : variable SerialPortEvent
location: class SerialTest
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
                                     ^
16 errors
MacBook-Pro:src user$ ls
RXTXcomm.jar        comm.jar        librxtxSerial.jnilib
SerialTest.java     librxtxParallel.so  librxtxSerial.so
MacBook-Pro:src user$ 
Run Code Online (Sandbox Code Playgroud)

难道我错过了另一个让这个工作的JAR吗?我没有看到这些类RXTXcomm.jar.

Rob*_*ert 5

RXTX库由两部分组成:首先是Java/Jar部分,第二部分是本机库.

如果Java可执行文件找不到本机rxtx库,则会出现错误.因此,您应该检查此本机库的位置.JNI库应该具有文件扩展名.jnilib.dylib.那么你有两种可能性:

  • 第一种可能性是将本机库复制到您启动Java的目录中(当使用Eclipse时,这是项目目录).

  • 第二种可能性是启动Java并指定本机库所在的库路径:

java -Djava.library.path=".:/Users/bill/rxtx/jni" MyClass 
Run Code Online (Sandbox Code Playgroud)