Instalando e Configurando RXTX no Ubuntu

Bom dia, Boa tarde, Boa noite meus amigos, recentemente comecei a enveredar novamento pelos caminhos de desenvolvimento de aplicações! Então vamos a um tutorial básico de instalação e configuração da biblioteca RXTX do Java para comunicação serial! 🙂

ps.: fico devendo uma tradução do post.

Links no fim do post.

1ª Etapa Instalação

RXTX is a full implementation of the Java CommAPI from Sun. It contains native libraries providing serial and parallel communication for the Java Development Toolkit.

A easy way to install RXTX on Ubuntu is using Synaptic Package Manager (Synaptic Package Manager is available in Ubuntu Software Center).

Simple search rxtx in Synaptic Package Manager, and mark to install

Install RxTx on Ubuntu with Synaptic Package Manager
Install RxTx on Ubuntu with Synaptic Package Manager

The jars will be installed in /usr/share/java folder.

– Alternatively, you can use the command in Terminal:
$sudo apt-get install librxtx-java

Remark: It copy the files only. To make it work with Java, you have to “Setup RxTx jar and .so for Ubuntu“.

2ª Etapa

Setup RxTx jar and .so for Ubuntu

The former post describe how to “Install RXTX on Ubuntu“. It simple download the files to your system, but Java not know where is it! To work with installed RxTx, you have to setup Build Path to compile the code, and copy the binaries (.so files) to java library path.

Setup Java Build Path in NetBeans:

If build path not set correctly, error of “package gnu.io does not exist” will be thrown.

package gnu.io does not exist
“package gnu.io does not exist” thrown without Build Path set

– Right click your project, select Properties.

Setup project properties
Setup project properties

– Select Libraries in Categories, Compiler tab and click Add JAR/Folder button.

Add JAR/Folder
Add JAR/Folder

– Browse to select RXTXcomm.jar, should be in /usr/share/java folder, and click OK to accept.

Add RXTXcomm.jar
Add RXTXcomm.jar

– Click OK again to finish. It should be compiled without error.

Copy the binaries (.so files) to java library path:

Without corresponding .so files in java library path, you will get error of “UnsatisfiedLinkError: no rxtxSerial in java.library.path” in run time, like this:

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread “main” java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1087)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:123)
at serialtest.SerialTest.initialize(SerialTest.java:41)
at serialtest.SerialTest.main(SerialTest.java:109)

UnsatisfiedLinkError
UnsatisfiedLinkError

– Refer to the post “Get property of java library path” to know where is the library folder.

– Copy the binaries librxtxSerial.so and librxtxParallel.so (should be in /usr/lib/jni/) to one of the library folder (for example: /opt/java/jre/lib/i386/).

$sudo cp /usr/lib/jni/librxtxSerial.so /opt/java/jre/lib/i386/librxtxSerial.so
$sudo cp /usr/lib/jni/librxtxParallel.so /opt/java/jre/lib/i386/librxtxParallel.so

Etapa bônus

Get property of java library path

To get current setting of java library path, call System.getProperty(“java.library.path”).

Example:

1
2
3
4
5
6
7
8
9
packagejavalibpath;
publicclassJavaLibPath {
    publicstaticvoidmain(String[] args) {
        String libPathProperty = System.getProperty("java.library.path");
        System.out.println(libPathProperty);
    }
}
Get property of java library path
Posts Originais
http://java-buddy.blogspot.com.br/2013/06/install-rxtx-on-ubuntu.html
http://java-buddy.blogspot.com.br/2013/06/setup-rxtx-jar-and-so-for-ubuntu.html
http://java-buddy.blogspot.com.br/2013/06/get-property-of-java-library-path.html
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s