Tomcat : Using RXTX with Tomcat applications on linux
This page last changed on May 30, 2013 by admin.
Install the proper linux package
apt-get install librxtx-java
Put the library on Tomcat's classpath
Add -Djava.library.path=/usr/lib/rxtx:/usr/lib/jni
to JAVA_OPTS
Houston we have a problem?
On booting the app RXTX reports the following:
Native lib Version = RXTX-2.2pre2
Java lib Version = RXTX-2.1-7
WARNING: RXTX Version mismatch
Jar version = RXTX-2.1-7
native lib Version = RXTX-2.2pre2
The Fix
- download the corresponding binaries from http://rxtx.qbang.org/wiki/index.php/Download
- place the RXTXComm.jar in
$TOMCAT_HOME/lib
- make sure no rxtx jars are included in the war file
- restart tomcat
The download site states:
TODO: The 2.2pre2 bins contain the 2.2pre1 jar file and the 2.2pre2 native lib which causes a mismatch warning
So not a problem after all? At least they are at the same minor version now.
Next issue: no ports found
See: http://blog.synyx.de/2013/03/running-rxtx-on-your-raspberry-pi/
Adding -Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0
as a startup parameter as suggested by this article did not make a difference.
The article also mentions:
To run the Java application later without root, we need a new user which has the privilege to access serial ports. To do so, just add a new user to group dialout
So in my case:
sudo adduser tomcat dialout