WildBill
WildBill

Reputation: 9301

Cannot run rxtx on Mac OS

I'm trying to use the rxtx JAR file for Java on a Mac (OSX 10.8). I've installed RXTXcomm.jar, the librxtxSerial.jnilib and accompanying .so files in /Library/Java/Extensions. I'm trying to execute the sample code at: http://arduino.cc/playground/Interfacing/Java

But I am apparently missing something as I get a bunch of cannot find symbol error messages.

Here are a couple:

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;

Is there something more basic I am missing within the installed Java on my machine? I've installed Xcode 4.5 just now, so I would think everything is there to run this simple code.

Folks have asked that I place the libraries in the same directory. Enclosed is an ls and the javac command I am running:

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

Is it that I am missing another JAR to make this work? I do not see these classes in the RXTXcomm.jar.

Upvotes: 1

Views: 2672

Answers (3)

Robert
Robert

Reputation: 42819

The RXTX library consists of two parts: First that Java/Jar part and second a native library.

The errors you get occur if the Java executable can not find the native rxtx library. Therefore, you should check where this native library is located. The JNI library should have the file extension .jnilib or .dylib. Then you have two possibilities:

  • First possibility is to copy the native library into the directory you are starting Java from (when using Eclipse this is the project directory).

  • Second possibility is to start Java and specify the library path where the native library is located:

java -Djava.library.path=".:/Users/bill/rxtx/jni" MyClass 

Upvotes: 5

maciekskontakt
maciekskontakt

Reputation: 11

If after those hints above it still does not work, potentially you have 32-bit RXTX library. On Macs that can run 32-bit apps you can force a client Java VM to work in 32-bit mode (as opposed to what some Java experts say). I managed this way to get rid of the UnsatisfiedLinkError by simply invoking java with -d32 option (mind the lower case as it isn't a Java system property).

My old program to communicate with an old RS-232 based programmer for Atmel processors started just nicely and works fine in 64-bit environment. However, bear in mind that with newer Macs and a 64-bit exclusive environment, that option may not be available - this is the main reason I still keep "dual" Mac OS X Snow Leopard on Core 2 Duo (updgraded from Core Duo with Dell notebook transplant processor) Mac Mini.

Upvotes: 1

HMarioD
HMarioD

Reputation: 842

Open the project properties pannel, go to libraries, select the button option Compile and click Add Jar/Folder, add the RXTXComm.jar to the list. That work for me. The compiler see the library because you put in the right place, then and as Netbeans says in the project properties pannel "Compile-time libraries are propagates to all library categories" we expect at run-time the same visibility but don't happen.

Upvotes: 0

Related Questions