Score:0

How to fix java.lang.ClassNotFoundException: gnu.io.CommPortIdentifier with libRXTX on Ubuntu 20.04?

us flag

I have the following error:

$ sudo java -jar /home/fadedbee/tc65sh-1.4.0/bin/tc65sh.jar -Djava.library.path=/usr/lib/jni/ -cp /usr/share/java/RXTXcomm.jar -p /dev/ttyUSB0 -b 115200 -f push.txt
tc65sh v1.4.0
processing command file push.txt
connecting /dev/ttyUSB0 with 115200 baud, flowControl r
Exception in thread "main" java.lang.NoClassDefFoundError: gnu/io/CommPortIdentifier
    at org.tc65sh.device.Device.connect(Device.java:56)
    at org.tc65sh.Main.exec(Main.java:102)
    at org.tc65sh.Main.main(Main.java:59)
Caused by: java.lang.ClassNotFoundException: gnu.io.CommPortIdentifier
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 3 more

I've installed libRXTX and all the files appear in the correct places:

$ ls -lA /usr/lib/jni/
total 148
-rw-r--r-- 1 root root 22696 May  9  2018 librxtxI2C-2.2pre1.so
lrwxrwxrwx 1 root root    21 May  9  2018 librxtxI2C.so -> librxtxI2C-2.2pre1.so
-rw-r--r-- 1 root root 14424 May  9  2018 librxtxParallel-2.2pre1.so
lrwxrwxrwx 1 root root    26 May  9  2018 librxtxParallel.so -> librxtxParallel-2.2pre1.so
-rw-r--r-- 1 root root 22688 May  9  2018 librxtxRaw-2.2pre1.so
lrwxrwxrwx 1 root root    21 May  9  2018 librxtxRaw.so -> librxtxRaw-2.2pre1.so
-rw-r--r-- 1 root root 22704 May  9  2018 librxtxRS485-2.2pre1.so
lrwxrwxrwx 1 root root    23 May  9  2018 librxtxRS485.so -> librxtxRS485-2.2pre1.so
-rw-r--r-- 1 root root 59824 May  9  2018 librxtxSerial-2.2pre1.so
lrwxrwxrwx 1 root root    24 May  9  2018 librxtxSerial.so -> librxtxSerial-2.2pre1.so

$ ls -lA /usr/share/java/ | grep RXTX
-rw-r--r-- 1 root root   63027 May  9  2018 RXTXcomm-2.2pre2.jar
lrwxrwxrwx 1 root root      20 May  9  2018 RXTXcomm.jar -> RXTXcomm-2.2pre2.jar

I can see the correct class inside of the jar file:

$ strings /usr/share/java/RXTXcomm.jar | grep CommPortIdentifier
gnu/io/CommPortIdentifier.class
gnu/io/CommPortIdentifier.classPK

How can I help Java find the class?

(I've already tried changing the option order to sudo java -Djava.library.path=/usr/lib/jni/ -cp /usr/share/java/RXTXcomm.jar -jar /home/fadedbee/tc65sh-1.4.0/bin/tc65sh.jar -p /dev/ttyUSB0 -b 115200 -f push.txt but the error remains.)

Bodo avatar
pt flag
Not directly related to your problem, but running the program as `root` might be a security risk. If you don't have the permissions to use `/dev/ttyUSB0` as a normal user you should add the user to the group that owns the tty device. see https://askubuntu.com/a/133244/1186757
fadedbee avatar
us flag
@Bodo, Yes, you're correct, but first I'll get it to run, then I'll sort out permissions.
Bodo avatar
pt flag
Did you recompile the sources or did you just run the binary JAR from `tc65sh-1.4.0.zip`? Just a guess: This seems to be a fairly old software, and the README file states "Java SE 6 must be installed on your machine to run TC65SH." Could there be an incompatibility between `tc65sh.jar` compiled probably with Java 6 and `RXTXcomm.jar` which might be compiled with a newer version or even might have changed.
N0rbert avatar
zw flag
Run first `sudo usermod -a -G dialout $USER` then reboot and retry without `sudo`.
fadedbee avatar
us flag
@Bodo I just ran the binary JAR.
Score:0
us flag

The solution was to use:

$ sudo java -Djava.library.path=/usr/lib/jni/ -cp /usr/share/java/RXTXcomm.jar:/home/fadedbee/tc65sh-1.4.0/bin/tc65sh.jar org.tc65sh.Main -p /dev/ttyUSB0 -b 115200 -f push.txt

It solves the first problem, but now I'm left with:

$ sudo java -Djava.library.path=/usr/lib/jni/ -cp /usr/share/java/RXTXcomm.jar:/home/fadedbee/tc65sh-1.4.0/bin/tc65sh.jar org.tc65sh.Main -p /dev/ttyUSB0 -b 115200 -f push.txt
tc65sh v1.4.0
processing command file push.txt
connecting /dev/ttyUSB0 with 115200 baud, flowControl r
RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyUSB0
initializing device
forcing obex mode
java.io.IOException: obex response timeout after 5001 ms and 33 bytes
    at org.tc65sh.device.Device.receiveObexResponse(Device.java:543)
    at org.tc65sh.device.Device.openObexMode(Device.java:326)
    at org.tc65sh.device.Device.obexOpenObexMode(Device.java:127)
    at org.tc65sh.Main.exec(Main.java:110)
    at org.tc65sh.Main.main(Main.java:59)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.