Search code examples
javamacosarduinorxtx

Java RXTX Library doesn't load native library


Basically i wanted to write a simple communication tool for my Arduino using the RXTX Library for java and failed horribly when it came to loading the dynamic library.

My system specs:
OS: OS X Yosemite 10.10.3
Java: SDK 1.8.0_45
RXTX: 2.1-7r2 - modified version for intel mac running 64 bit java, which can be found here.
IDE: NetBeans 8

I checked, that these files work by following the install instructions, which is simply copying these two files into the /Library/Java/Extensions directory.

Now I wanted to remove them and load the library from my application. I did the following:

  • Add the RXTXcomm library to the project in netbeans.
  • Includ the container of the native library in the "java.library.path" property using the following piece of code

System.setProperty("java.library.path", location.getPath() + File.pathSeparator + System.getProperty("java.library.path"));

  • And load the library using System.loadLibrary("rxtxSerial")

When I compiled the code and tried to run it, it gave me an
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path

Now I'm wondering what i have done wrong (maybe some great misunderstanding?)

Any help would be appreciated!


Solution

  • In addition to my recent reply this one.

    This is the code to delete the mentioned cache:

    try {
        Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
        fieldSysPath.setAccessible(true);
        fieldSysPath.set(null, null);
    } catch (NoSuchFieldException |
            SecurityException |
            IllegalArgumentException |
            IllegalAccessException ex) {
        ex.printStackTrace(System.err);
    }
    

    So the issue was not the rxtx library but rather my own failure to read the java doc. Because I'm sure this is mentioned somewhere right at the beginning.