【发布时间】:2012-10-02 11:13:58
【问题描述】:
我正在尝试在 Mac (OSX 10.8) 上为 Java 使用 rxtx JAR 文件。我已经在/Library/Java/Extensions 中安装了RXTXcomm.jar、librxtxSerial.jnilib 和随附的.so 文件。我正在尝试在以下位置执行示例代码: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;
在我的机器上安装的 Java 中是否缺少一些更基本的东西?我刚刚安装了 Xcode 4.5,所以我认为一切都可以运行这个简单的代码。
人们要求我将这些库放在同一目录中。随附的是 ls 和我正在运行的 javac 命令:
$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$
是我缺少另一个 JAR 来完成这项工作吗?我在RXTXcomm.jar 中没有看到这些类。
【问题讨论】:
-
听起来像是类路径问题。你是如何运行你的代码的?
-
通过 Eclipse 通过简单地运行“编译”或在命令提示符下使用简单的“javac SerialTest.java”。如果 jar 在 /Library/Java/Extensions 中,我相信这就是我需要做的,对吗?我也尝试了 -cp "/Library/Java/Extensions" ,但仍然得到相同的结果。
-
听起来像是类路径问题。你是如何运行你的代码的?请尝试以下操作:将所有文件,包括共享库、jar 文件和示例类,复制到同一目录,然后 cd 到该目录。然后,从您的 shell 中,执行 javac -classpath RXTXcomm.jar:。 SerialTest.java 然后,执行 java -Djava.library.path=。 -cp RXTXcomm.jar:.串行测试
-
所有文件都在同一个目录下,上面的方法还是不行:(