Using RXTX
From Rxtx
This page is for general content regarding the use of rxtx. Feel free to add your own content.
I wrote an app several months ago using javax.comm on windows. Sun has left me high and dry. rxtx help!
- download ftp://ftp.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip
- unzip it
- copy rxtxSerial.dll into your c:/program files/java/jre-version/bin dir
- copy RXTXcomm.jar into your c:/program files/java/jre-version/lib/ext dir
- change all references from 'javax.comm' to 'gnu.io'
- recompile
- test
Dido Sun left me Hi and dry. After 30+ hours wasting my life on javax.comm it is the RXTXcomm 2.1.7 that really worked the first time
REMEMBER !! for the newbies Change the all occurences of the import javax.comm.*; in MyApps.java TO import gnu.io.*; I did not even have to recompile as suggested the rxtxSerial.dll
a job well done for the rxtx.org team.
Even after following the above instructions, under Netbeans 5.5 on Windows, I needed to right-click Libraries under Projects on the left hand side of the screen, and select Add JAR/Folder, picking the RXTXcomm.jar file. Only then did my "import gnu.io.*;" become a valid command. Also, I got a run-time error where it failed to load the rxtxSerial.DLL library because it couldn't find it. I needed to right-click the project name, select properties, select Run under categories, and ...
add a VM Options: entry of -Djava.library.path="C:/where-ever-you-stuck-rxtxSerial.DLL-file;%PATH%" While I'm sure there is more than one way of adding the directory to your path, this worked for me. Note I did the default NetBeans 5.5/JDK 1.6.0 isntall accepting all the default options(ie clicking next until I got to finish), so I haven't modified my java paths or anything.
Using RXTX In Eclipse
From Rxtx
This is how I add and use RXTX in Eclipse for Win32 Projects, there are probably other ways but it works for me. mailto:seaton@gateway.net.au
- Copy RXTXcomm.jar file and dll files to the lib directory of your project
- Under Project | Properties | Java Build Path | Libraries
- click Add JARs... Button
- Select the RXTXComm.jar from lib directory
- Jar should now be in the Build Path
- expand the RXTXComm.jar entry in the list and select "Native Library Location"
- Select the project lib directory and apply
Be careful when using System.in.read() and rxtx in win32; It can trip across a known JRE deadlock (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4809647) bug
Deploying JAVA with RXTX
From Rxtx
Saving the RXTX jar-file and DLL in the JRE is not optimal if you indend to distribute your JAVA application and do not want to bundle it with a customized JRE.
Windows
For Windows, the Janel (http://sourceforge.net/projects/janel) JAVA launcher can be used.
- create a directory for your application, and save the Janel executable and lap-file to it;
- create a subfolder named "classes" and save the jar-file of your application as well as the RXTXcomm.jar in it;
- create a subfolder named "lib" and save the rxtxSerial.dll to it;
- make the following entries in the lap-file:
- "-Djava.class.path=;${SELF_HOME}/classes/YourApp.jar;${SELF_HOME}/classes/RXTXcomm.jar;"
- "janel.main.class=YourAppMainClass"
- "janel.library.path.dir=${SELF_HOME}/lib"
unjar
It should be possible to unjar the RXTXcomm.jar and then add the .classes into YourApp.jar. This should eliminate the secon .jar and the need to modify java.class.path. Please clarify the steps if you pursue this.
I was successful in doing this on my Mac. First, unzip the RXTX.jar file. I didn't try unjar, as unzip worked fine. Then, place the gnu folder in the same folder as your application jar file. Execute the following command from the command line:
jar uvf Your_Apps_Name_here.jar gnu
to update the jar with the contents of the classes in the gnu folder. Your app will now run by double clicking on it, provided the .dll or .jnilib library is in the same folder. I would love to include the OS specific libraries in the jar for a single, monolithic package, but after researching this on the web, it is apparently very difficult at best and probably impossible.
Other Platforms
It would be great if someone with access to Linux boxes could provide us with similar recipes for their operating system.
The above unjar instructions and subsequent jars worked fine for my app on both Mac and Windows machines.