Serial Port Communication for Java SE Embedded

The need to communicate with devices connected to serial ports is a common application requirement.  Falling outside the purview of the Java SE platform, serial and parallel port communication has been addressed with a project called RXTX.  (In the past, you may have known this as javacomm).  With RXTX,  Java developers access serial ports through the RXTXcomm.jar file.  Alongside this jar file, an underlying native layer must be provided to interface with the operating system's UART ports.  For the usual suspects (Windows, Linux/x86, MacOS, Solaris/Sparc), pre-compiled binaries are readily available.  To host this on an alternative platform, some (hopefully minimal) amount of work is required.

Here's hoping the following notes/observations might aid in helping you to build RXTX for an embedded device utilizing one of our Java SE Embedded binaries.  The device used for this particular implementation is my current favorite: the Plug Computer.

Notes on Getting RX/TX 2.1-7-r2 Working on a Plug Computer

1. At this early juncture with Java 7, be wary of mixing Java 7 with code from older versions of Java. The class files generated by the JDK7 javac compiler contain an updated version byte with a value that results in older (Java 6 and before) JVMs refusing to load these classes.

2. The RXTX download location has binaries for many platforms including Arm variants, but none that worked for the Plug Computer, so one had to be built from source.

3. Using the native GCC for the Plug Computer and the RXTX source, binaries (native shared objects) were compiled for the armv5tel-unknown-linux-gnu platform.

4. The RXTX "stable" source code found at the aforementioned site is based on version rxtx 2.1-7r2.  This code appears to be pretty long in the tooth, in that it has no knowledge of Java 6.  Some changes need to be made to accommodate a JDK 6 environment.  Without these modifications, RXTX will not build with JDK6

SUGGESTED FIX, most elegant, not recommended:
Edit the file in the source directory and look for the following:

    case $JAVA_VERSION in

and change the second line to:


Upon modification, the script found in the rxtx source directory must be re-run to recreate the ./configure script.  Unfortunately, this requires loading the autoconf, automake and libtool packages (plus dependencies) and ended up resulting in libtool incompatibilies when running the resultant ./configure script.

Instead, edit ./configure and search for the occurrences (there are more than one) of

    case $JAVA_VERSION in

and change the second line to:


Run './configure', then 'make' to generate the RXTXcomm.jar and platform specific .so shared object libraries.

5. You may also notice in the output of the make, that there were compilation errors for source files which failed to find the meaning of "UTS_RELEASE".  This results in some of the shared object files not being created.  These pertain to the non-serial aspects of RXTX.  As we were only interested in, this was no problem for us.

6. Once built, move the following files into the following directories:

    # cd rxtx-2.1-7-r2/
    # cp RXTXcomm.jar $JAVA_HOME/lib/ext
    # cd armv5tel-unknown-linux-gnu/.libs/
    # cp $JAVA_HOME/lib/arm
    # cd $JAVA_HOME/lib/arm
    # ln -s

Now Java applications which utilize RXTX should run without any java command-line additions.

The RXTXcomm.jar file can be downloaded here.  To spare you the effort, a few pre-built versions of are provided at this location:

If you've gone through this exercise on any additional architectures, send them my way and I'll post them here.


Many thanks for including the compiled library, that saved me a huge headache.

Posted by Ali Naddaf on February 10, 2012 at 12:31 AM EST #

Thanks Jim,

Worked a treat... compiled nicely for armV7l (tegra2). Well... a few warnings and errors came up but it worked! i can send you the .so and .jar files if you like to make them available for this architecture.

- Dan.

Posted by Dan on February 10, 2012 at 01:24 AM EST #

By all means! You supply the binaries and I'll post them.

Posted by Jim Connors on February 10, 2012 at 08:13 AM EST #

i am new to this can you please guide me how to use thisi need to send data through rs232 from pc

Posted by guest on March 22, 2012 at 07:16 AM EDT #

Gary Collins recently got his hands on one of the much ballyhooed Raspberry Pi devices, and was kind enough to provide the native share object for this armv6l based platform. It is now listed as one of the provided pre-build versions.

Posted by Jim Connors on July 10, 2012 at 05:58 PM EDT #

Thank you for compiled library. Now I am able to combine my electronics with Qnap (environment temperature reporter). Greetings.

Posted by guest on August 06, 2012 at 04:18 PM EDT #

I have tried the for ARMv6l based systems (e.g. Raspberry Pi), on my Raspberry Pi running OpenJDK 1.6 on Arch Linux

Unfortunately, I don't believe it has the fix. I get "java.lang.UnsatisfiedLinkError:; thrown while loading" which would be the message I believe if the .so did not have the fix.

Posted by Greg on October 03, 2012 at 10:58 AM EDT #

Your problem may lie in the fact that the Raspberry Pi Arch Linux distro uses the armhf (hard float) ABI which is incompatible with the armel-based version of the which was originally provided here. I've been patiently waiting and just received my very own Raspberry Pi. When I get a chance, I'll try compiling an armhf version under the Raspbian (armhf) distro.

Posted by guest on October 11, 2012 at 12:42 PM EDT #

Updated to include files for both armel and armhf based Raspberry Pi distributions.

Posted by guest on October 11, 2012 at 06:45 PM EDT #

Has anyone compiled and tested rxtxlib for the BeagleBone? I tried pre-built versions ARMv6 for armhf and it works 3 hours when crashed. This happened repeatedly.
I would be very happy if somebody upload version that fits to BeagleBone.

Posted by guest on January 19, 2013 at 02:30 AM EST #

For Linux why not use socat and then use sockets from Java ?

Posted by guest on March 19, 2013 at 04:15 AM EDT #

I posted earlier that rxtxlib with BeagleBone crashed within 3 hour use. I have found out that problem didn't focused on rxtxlib. Reason came up from Huawei E367 netstick that is used as dial-up modem. This device seems not not to be so reliable.

Posted by guest on March 19, 2013 at 02:00 PM EDT #

Running RXTX as an OSGi bundle allows to dynamically choosing the right native lib to load based on system properties (see OSGi "Bundle-NativeCode" manifest tag).

Unfortunately, running the Oracle JVM 1.7.0 does not allow to distinguish the version of the ARM processor (V.5/6/7) using the system propertie. The "os.arch" is just "arm". Also, for ARMv6 (Raspberry Pi), it should be possible to distinguish between HF and SF.

How can the dynamic choice of the native lib be done?

Posted by Philipp on April 02, 2013 at 10:53 AM EDT #

This is currently not an easy problem to solve. Ironically I wrote a related blog entry entitled "Is it armel or armhf?". In there you'll find a pointer to a Raspberry Pi forum entry which discusses your exact question.

Posted by Jim Connors on April 02, 2013 at 10:07 PM EDT #

the website is not available now. anybody know how to download the native source ?

Posted by guest on June 18, 2014 at 03:13 AM EDT #

Been meaning to do this for a while, check out this blog entry:

Java Serial Communications Revisited

Among other things it points to RxTx source code with some very minor modifications.

Posted by Jim Connors on June 20, 2014 at 03:14 PM EDT #

please add tag "raspbian" and "raspberry pi"

thanks :)

Posted by guest on March 24, 2016 at 01:02 AM EDT #

Done. Added "raspbian" and "raspberry-pi" tag to this blog and the preferred, updated version -

Posted by Jim Connors on March 24, 2016 at 08:43 AM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Jim Connors-Oracle


« April 2016