Home > Utility > Java 6 and librxtxSerial.jnilib on Intel Mac OS X

Java 6 and librxtxSerial.jnilib on Intel Mac OS X

[UPDATE: This library works with Mac OS X 10.6 Snow Leopard.]

In order to access a serial port in Java, you need the RXTX libraries compiled for your specific hardware. Java uses the Java Native Interface (JNI) to bridge between your platform-independent application code and the hardware-specific serial port drivers.

If you’ve tried this on an Intel Mac (perhaps to play with a Sun SPOT), you may be disappointed, since software keeps shipping from people that is either PowerPC only or isn’t compiled for 64-bit Intel. You’ve probably seen the UnsatisfiedLinkError message. Here you’ll find a librxtxSerial.jnilib file with support for both 32- and 64-bit PPC and Intel architectures, fitting the bill perfectly for both Java 5 and Java 6 on the Mac.

$ file librxtxSerial.jnilib
librxtxSerial.jnilib: Mach-O universal binary with 4 architectures
librxtxSerial.jnilib (for architecture x86_64):	Mach-O 64-bit bundle x86_64
librxtxSerial.jnilib (for architecture i386):	Mach-O bundle i386
librxtxSerial.jnilib (for architecture ppc7400): Mach-O bundle ppc
librxtxSerial.jnilib (for architecture ppc64):	Mach-O 64-bit bundle ppc64

The Need for the RXTX Library

Java’s “write once, run many” theory of operation works because the Java Virtual Machine (JVM), which must be made for each platform, abstracts away the underlying hardware. As a programmer you can draw circles, label buttons, and even play multimedia without specific knowledge of the host operating system.

A computer’s serial ports can be abstracted away in the same way, but the standard JVM does not provide a mechanism for this. Sun decided (reasonably, though regrettably, I think) that the serial port would not be a required component for a JVM, and so there are no built-in classes for working with serial ports.

Sun experimented, for a period of time, with a Java Communications API that would be a sort of plugin for working with things like serial ports (and parallel ports!), but the project and its javax.comm package died.

Thanks to the team at RXTX.org, we now have a gnu.io package modeled after Sun’s javax.comm package that is maintained and works. Thanks!

Why Doesn’t It Work for You?

If you’re reading this, it might be because you can’t get it to work on your Mac. Probably you have an Intel Mac and are using Java 6 or later which requires a 64-bit Intel processor. Perhaps you’ve seen error messages that say thinks like UnsatisfiedLinkError and so forth.

Software talking to the serial port must communicate with the host operating system, and so the underlying native library must be compiled per-platform. Presumably your librxtxSerial.jnilib file is not compiled for your platform. Here’s how to find out. Open the Terminal, navigate to the folder with a librxtxSerial.jnilib file, and use the file command. You’ll probably see this:

$ cd /Users/rob/SunSPOT/sdk/lib
$ file librxtxSerial.jnilib
librxtxSerial.jnilib: Mach-O universal binary with 2 architectures
librxtxSerial.jnilib (for architecture i386):	Mach-O bundle i386
librxtxSerial.jnilib (for architecture ppc7400): Mach-O bundle ppc

If you’re running Java 5 (which comes in 32- and 64-bit flavors on the Mac) you’re OK, but if you’re running Java 6, which is 64-bit Intel only, it won’t work.

A Library with the Right Architectures

No problem; all you have to do is re-compile RXTX from sources for your platform, right? I wish. I can’t even remember all the contortions I went through before I finally got it compiled.

You’re welcome to follow the various instructions online for compiling it yourself, but it gave me a lot of grief, so I’m placing a copy on this site (if you trust me not to insert nefarious code). I finally had to patch SerialImpl.c and SerialImpl.h (manually) based on the patch instructions here and blog posting here.

At the end of the day, we have a librxtxSerial.jnilib file that has 32- and 64-bit PPC and Intel architectures.

Find all instances of librxtxSerial.jnilib on your Mac and replace them with the one you downloaded from here (or compiled yourself). Try the command locate librxtxSerial.jnilib in the Terminal to find extra copies hidden in various Java applications.

Categories: Utility Tags:
  1. Rui
    October 15th, 1999 at 01:47 | #1

    Hi guys, not working on El Capitan. I downloaded jni lib and put the jar inside Extensions dir, but when I open my project on Intelli J, still not working. Any idea?


  2. Pete
    October 12th, 2009 at 05:32 | #2

    THanks man, save me trying out the hours of compiling you went through! I’m wondering, will the .jar from RXTX be the one I need for the jnilib? It looks like it’s working so far.

    • October 12th, 2009 at 08:20 | #3

      Yes, the standard .jar file from rxtx should be fine. Happy coding to all. -Rob

  3. Patrick
    November 1st, 2009 at 22:07 | #4

    Thanks for the post. It’s a really useful info!!

    A quick question, do I need to compile 64-bit .dll if I want to use rxtx with JDK6 in Windows environment?

    • November 1st, 2009 at 22:34 | #5

      Good question. I suppose if you have 64-bit Windows with a 64-bit Java then you’d need a 64-bit RXTX library. I’m sorry I don’t have one compiled for you. -Rob

  4. Peter
    November 4th, 2009 at 18:56 | #6

    Robert, I had been banging my head against the wall for a couple of days until now. Thanks you so much for working better than Tylenol.

  5. andrew
    November 25th, 2009 at 09:55 | #7

    thanks for sharing. btw, java comm. is not dead, but they discontinued support for windows and never supported mac.

  6. SP
    February 3rd, 2010 at 20:09 | #8

    Can you please also post RXTXcomm.jar file?


  7. February 4th, 2010 at 00:31 | #9

    Rather than post stale files, and in keeping with good practices, here’s the link to the download page, if you’re having trouble finding it:



  8. February 20th, 2010 at 09:47 | #10

    just to be sure… which of the 3/4 versions available in the qbang download page is the one you used for this compile?
    Thanks a lot

  9. February 20th, 2010 at 18:13 | #11

    I don’t remember, but surely I chose the line that reads, “rxtx 2.1-7r2 (stable) rxtx-2.1-7-bins-r2.zip rxtx-2.1-7r2.zip.” -Rob

  10. February 21st, 2010 at 17:47 | #12

    Hi again Robert and thanks for your help…
    I can only put to work rxtx-2.2pre2 with the built in file (3 architectures including Mach-O 64-bit bundle x86_64). I anyway get a full JVM crash when I am finished and do SerialPort.close().
    With rxtx 2.1-7r2 and your jndi file I get a gnu.io.PortInUseException: Unknown Application at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)
    Thanks for any directions 🙂

  11. February 23rd, 2010 at 11:14 | #13

    Ignacio, I’m sorry that I can’t think of anything really useful to try, but if you have other versions of java on your Mac, you might try running your code with them just to see if the crash is unique to one version or another. -Rob

  12. Stephane D.
    March 5th, 2010 at 04:17 | #14

    Thank you a lot for your help!! I can finally do my application work on Max OS 10.6 . Your librxtxSerial.jnilib fix my problem.
    Have a good day!

  13. Christoph
    March 25th, 2010 at 13:56 | #15

    @Ignacio: The problem is with the lock file. See http://atelier.tkrworks.net/doc/about-picnomeserial?lang=en how to fix it

  14. Art
    April 11th, 2010 at 18:48 | #16

    Worked splendidly for me on Snow Leopard, after I created the /var/lock file directory (didn’t work without that change). The RXTX installation page talks about how to create the lock file directory using the fixperm.sh script. That page correctly tells you that you need to modify the path in the script to /var/lock, but the script uses niutil, which apparently isn’t part of Snow Leopard anymore. The instructions Christoph pointed to are better.

  15. Joe
    May 29th, 2010 at 11:13 | #17

    Thank you so much, its always nice to find someone else with the same problem who has managed a solution.

  16. Dave
    June 3rd, 2010 at 17:13 | #18

    Thanks for making this jnilib available. Works great on my Mac. Now if I could just find a solution for the kernel panics caused by the Silabs CP210x Mac virtual com port driver. Anyone else running into that?

  17. Dietmar
    September 11th, 2010 at 00:09 | #19

    Thanks Robert for your work.

    Now also Mac OS 64bit users can use you vna/J.

    Have a nice day ahead

    Dietmar, DL2SBA

  18. September 15th, 2010 at 00:00 | #20

    THANK YOU for your hard work. I really appreciate the time you saved me in recompiling the rxtx jnilib and making it available to the world.

    Am on OS X 10.6, was able to get my serial app launched using your jnilib and then fixed the “gnu.io.PortInUseException: Unknown Application” issue with instructions posted in comments above: http://atelier.tkrworks.net/doc/about-picnomeserial?lang=en


  19. WHY
    November 22nd, 2010 at 08:09 | #21

    Thank you SO much!! My application finally works with your librxtxSerial.jnilib.

    however, still there is a problem. My device is connected to a MACBook thorugh a usb-serial adaptor. The application can only run once correctly, if I colse the appliction, start again, it will not able to access the serial port. I have to unplug and plug again the usb-serial port adaptor. Do you think anything wrong?

  20. November 22nd, 2010 at 10:27 | #22

    @WHY That happened to me before, and I’m trying to remember how I resolved it. I think what it came down to was that the JVM wasn’t releasing the virtual machine, but I don’t remember how that was happening even after I had closed the Java app. I don’t remember what I did to fix it, or if it just stopped on its own.

  21. Seb
    January 26th, 2011 at 11:59 | #23

    Thank you very much for this. I was trying to find out why it was not working on my macbook until I realised I was running 64-bit.

  22. May 2nd, 2011 at 12:01 | #24

    Mr. Harder:

    Thanks a bunch for the modified librxtx.Serial.jnilib file. It solved a problem we were having with MorseKOB on the Mac, a program that some of us old (and new) telegraph operators use to communicate in authentic landline Morse code (url below).

    Problem was that using the Options to change either the Mode or Port resulted in the browser crashing.

    Thanks again!

  23. togarha
    May 12th, 2011 at 01:42 | #25


    I’m an user of rxtx library, I’m trying to compile the rxtx library for mac osx as you say in your web, but I can’t get the same result as you. I can’t compile for ppc64. If I put only -arch i386, -arch ppc, -arch x86_64 it doesn’t not compile for ppc64, If I try to compile with -arch ppc64 the compilation makes error…

    Furthermore, my compilation doesn’t work with x86_64 with java6. Your file works fine, but I want this file without lock files, this is why I want to compile a new file…

    I hope you can help me…


  24. May 12th, 2011 at 07:01 | #26

    I’ve been meaning to try to recreate my compilation instructions. Maybe I can get around to that. I don’t remember for sure, but I think I had to compile PPC separately and merge it with the other architectures. I don’t remember if I had to do it on a PPC machine or not, but I’m pretty sure it was pre-Snow Leopard, and I hope I still have the ability to cross compile to PPC.

  25. togarha
    May 12th, 2011 at 11:04 | #27

    Really I don’t need the ppc compilation, I only need x86_64, but my compilation doesn’t work in x86_64 (making changes you say)

  26. Stefan
    May 20th, 2011 at 08:13 | #28

    I got an gnu.io.PortInUseException on OS X 10.6.7 (x86_64) Macbook Air and had to run:

    sudo mkdir /var/lock
    sudo chmod a+wrx /var/lock

    in the terminal to get it working…

    Thanks for the effort!

  27. August 7th, 2011 at 15:37 | #29

    Many thanks!
    This works with Stefan’s fix on OSX Lion 64-bit Intel.

  28. Thomas Kilian
    August 28th, 2011 at 13:23 | #30

    Thanks for that. I got a message that the file was not on my Lion system. Indeed there was a symbolic link and a directory with that name in /Library/Java/Extensions. But no real contents. I removed the link and the directory, placed librxtxSerial.jnilib there and my problems were gone.

  29. September 9th, 2011 at 11:59 | #31

    I have downloaded your modified librxtxSerial.jnilib on my 10.6.8 Snow Leopard machine. But I still get the following problem.

    CommPortIdentifier:static initialization()
    WARNING: RXTX Version mismatch
    Jar version = RXTX-2.2pre1
    native lib Version = RXTX-2.1-7
    Exception in thread “main” java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1045)
    at hts.HTS_UI.(HTS_UI.java:689)
    Experimental: JNI_OnLoad called.

    Please bear in mind that my Java skills are quite primitive.


  30. September 9th, 2011 at 12:16 | #32

    @Phil Try running the command “file $(which java)” (no quotes) and see what architectures you’re shown. There should be overlap with librxtxSerial.jnilib. It’s possible that Java is loading a pre-existing librxtxSerial.jnilib file w/o the right architectures. Look for other librxtxSerial.jnilib files and replace them perhaps.

  31. Jim Hannon
    September 23rd, 2011 at 04:31 | #33

    Thanks so much for the library file. Works great for me. I appreciate it.

  32. Rose G
    November 8th, 2011 at 20:28 | #34

    Hi I am using Mac OSX Lion 10.7 and receiving the following:
    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

    I’ve tried so many solutions such as changing location of the rxtxSerial from extension to the actual src file of my java project as well as using Java 5..

    Any Suggestions?

    • November 8th, 2011 at 21:41 | #35

      I haven’t tried it since going to Lion, nor do I have a way to test it out right now. Sorry. -Rob

  33. Tom
    November 30th, 2011 at 06:19 | #36

    Works great on Lion. Thanks a lot!

  34. Suhas
    January 31st, 2012 at 12:09 | #37

    If you get Portinuse exception, then please do following


    As a nice anonymous user comments, these are the steps to go:
    Open ‘Terminal’ from Applications->Utilities
    Enter the commands:
    sudo mkdir /var/lock (hit enter end type your password)
    sudo chmod 777 /var/lock (hit enter again)

  35. March 5th, 2012 at 19:25 | #38

    @Rose G, the instructions from Suhas fixed that problem for me. Thank you so much!

  36. nandish
    April 9th, 2012 at 11:16 | #39

    Thanks it worked for me

  37. Diego Beltrán
    August 6th, 2012 at 15:33 | #40

    Very impressive Work, thank you so much.

  38. Girts
    September 26th, 2012 at 07:50 | #41

    Thank you very much, you saved a lot of time for me! 🙂

  39. November 8th, 2012 at 18:36 | #42

    Thanks a lot for your great work! It helped me a lot. I tested everything the last maybe even more then 7 days. This knowhow i would like to share, just in case somebody else has the same problems. The Version from Robert Harder is 2.1-7. With this Version you have to build a var/lock directory with the right permissions. The problem is that from Mac OS 10.5 this directory isn’t installed. The problem is also that the error message is portinuse-exception. Even the port is not in use. Just the directory is missing. You can loose a lot of time to find the solution this way. RXTXcomm.jar Version 2.2 doesn’t need this var/lock-directory. I tested really almost all possibilities from Cloudhopper to jlog and so far. There are always some disadvantages. Cloudhopper for example doesn’t support Mac. If you do it like I write her, you can save a lot of time. It works for all OS. Go to http://rxtx.qbang.org/wiki/index.php/Download. Download rxtx-2.2pre2-bins.zip. Take RXTXcomm.jar and put it to Java/lib/ext on Windows or Java/Extensions on Mac. For Windows and Linux take the 32 or 64 Bit version of rxtxserial.dll or librxtxserial.so. For Mac OS 10.5 and lower take librxtxserial.jnilib. In Windows put rxtxserial.dll to Java/bin/. On Mac put it to Library/Java/Extensions. There is no librxtxserial,jnilib for 64-bit Mac. OS 10.6 and higher are always 64-bit. The right file you find here: http://code.google.com/p/create-lab-commons/source/browse/trunk/java/lib/rxtx/ Download librxtxSerial64.jnilib. RXTXcomm.jar won’t find librxtxSerial64. You have to rename it to librxtxSerial.jnilib. Put it to Library/Java/Extensions. Like this everything works without creating a var/lock-directory and troubleshooting around the wrong Error Message portinuse-Exception. Anyway it’s better to have Version 2.2 instead of 2.1-7 if there are not any other issues. I didn’t find any so far.

    2 hints at the end. On Mac with Version 2.1-7 and 2.2 the program crashed at serialPort.Close;. It took me a hell of time until i found out that there must be a serialPort.removeEventListener(); before serialPort.Close; even I didn’t open AddEventListener. This must be a bug. Just put serialPort.removeEventListener(); and everything works fine.

    The second hint: I use usb to serial adapter to open a cashdrawer. The first time when i was writing out the Esc-String it was working. But then nothing was writing out any more. But the program finished successfully. Without any error. Very strange. I found out when i write out twice or more times outputStream.write(messageString.getBytes()); then everything worked fine. It was doing the first write and also the second. But when i wrote just one time outputStream.write(messageString.getBytes()); it was just working the first time. Then i could klick a 100 times it didnt’t work any more. I do it now like this:
    var justwriteanything = “rrrr”;
    outputStream.write( justwriteanything.getBytes());

    this way it works always. Strange but true.

  40. rjlzaitz
    November 17th, 2012 at 22:55 | #43

    Thank You! I’ve been losing my mind over this all day. Trying to open a serial connection via bluetooth between my Arduino and Processing. This fixed it.

  41. Jonathan
    November 26th, 2012 at 00:15 | #44

    Thank you so much for posting this!

    On my other development machine, I forced the compiler into 32-bit mode and on my second machine, I’m using your file.


  42. ajayp
    December 11th, 2012 at 19:28 | #45

    just a heads-up that this works on mountain lion 10.8.2 as well. thanks sir, this is super duper extra appreciated.

  43. George
    December 11th, 2012 at 23:01 | #46

    I can’t seem to get it to install correctly in OSX 10.7.5 machine. I put both files: RXTXcomm.jar and librxtxSerial.jnilib (originally downloaded as librxtxSerial64.jnilib)
    in /Library/Java/Extensions
    I am using Eclipse Indigo r2, and have added RXTXcomm.jar into the build path of my project. I am getting error messages on the “import gnu.io.xxxxx” lines.
    Any suggestions?

  44. George
    December 11th, 2012 at 23:48 | #47

    I just saw the error message in Eclipse telling me that the file Archive for required library: /Library/….. /RXTXcomm.jar in project xxx “cannot be read or is not a valid zip file”. I have an extension installed that allows me to look into the contents of the .jar’s and the contents look fine. In fact all my projects had the error and I had to remove the entire JRE system library from each project and add it back in again. I assume this is some kind of Eclipse issue and not Java per se.

  45. George
    December 12th, 2012 at 07:17 | #48

    Problem solved. I had a Processing plugin installed on Eclipse and it had a 32 bit version of the librxtxSerial.jnilib. I should have read this post more carefully, especially this quote:

    “Find all instances of librxtxSerial.jnilib on your Mac and replace them with the one you downloaded from here ”

    and not jumped around to the latest comments. Lesson learned.

  46. February 15th, 2013 at 21:38 | #49

    Tomb Raider, Mega Moolah, Mermaid’s Millions, and Blackjack are some of the new Android game apps that have been released from Microgaming’s partner,
    Spin 3. You will eventually run into the Download Location menu with two options: Wii System Menu and
    SD Card. A Twitter app for Zune has been created and is now available for download
    through Microsoft’s Marketplace.

  47. Jake
    March 9th, 2013 at 03:36 | #50

    Thanks so much – worked a treat. Been trying to find a solution to this for ages.

  48. June 26th, 2013 at 18:17 | #51

    Heya! I just wanted to ask if you ever have any problems with hackers?
    My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to
    no data backup. Do you have any methods to stop

  49. July 14th, 2013 at 15:36 | #52

    Oh my goodness! Incredible article dude! Many thanks, However I am experiencing issues with your RSS.
    I don’t understand the reason why I cannot join it. Is there anyone else having the same RSS problems? Anyone that knows the answer can you kindly respond? Thanx!!

  50. Doug Squires
    December 26th, 2013 at 20:58 | #53

    Holy schmoly. Thanks for the lib. I’m working on a silly hobby project and did not want to spend any more time trying to get this stupid thing to build – including finding jdk headers, etc. wowza.

  51. David
    May 4th, 2015 at 11:03 | #54

    I just stumbled upon new serial port library which seems promising and save my time to build for different operating systems https://github.com/RishiGupta12/serial-communication-manager

  52. David Sosa
    November 21st, 2017 at 04:10 | #55

    @Marcel Fiechter
    Thanks man! your comment saves my day! kind regards from the Canaries!

  53. bandfernmohn
    January 14th, 2018 at 07:56 | #56

    Thanks a lot! Already fell into despair until I found your site here! You made my day. Thanks for sharing!

  54. Nalin Luthra
    October 30th, 2018 at 00:05 | #57

    I am trying to download “librxtxSerial.jnilib” but it is showing error 404, I guess link to file is somehow got deleted.

    Please check it and I will be grateful if you can solve it.

  1. September 18th, 2012 at 10:44 | #1
  2. December 13th, 2012 at 16:58 | #2
  3. March 9th, 2013 at 03:50 | #3
  4. October 8th, 2014 at 23:37 | #4
  5. October 10th, 2014 at 09:43 | #5
  6. April 24th, 2015 at 18:34 | #6
  7. July 3rd, 2015 at 17:58 | #7
  8. July 22nd, 2015 at 12:34 | #8
  9. February 21st, 2016 at 20:41 | #9