1

Have Java program running on Windows and Raspberry Pi. When running the program on Pi, I need to use -Djava.library.path=/usr/lib/jni

when I run the jar so the RXTX libs can be found. I want to do it in code with System.setProperty(), but it doesn't work.

Any known issues with setProperty() on Pi?

Verified so files on Pi are in /usr/lib/jni. Print out shows path is being sent to setProperty() as expected.

    if (doPi == true)
        s = "/usr/lib/jni"; // Pi so files
    else
        s = "C:\\Program Files (x86)\\Java\\jre1.8.0_181\\bin"; // Win dll files

    System.setProperty("java.library.path", s);
    System.out.println("Java lib path " + s);

I expected the setProperty() code would allow me to not need

-Djava.library.path=/usr/lib/jni

When running the jar file.

But without it, I get an error that the RXTX lib files are not found.

Pang
  • 9,564
  • 146
  • 81
  • 122
David D
  • 31
  • 3

1 Answers1

0

I think the problem is that the path to the RXTX lib files need to be set before starting the application. So setting it using the System.setProperty() method is probably working, but it sets the property after the programm started, and therefore after the property was read.

I'm using the RXTX lib on RaspberryPi for quite a while now and I haven't found a way to start this applications without the command line parameters. The easiest way to start the application probably is a small bash script.

Another way would be to not use RXTX (which is quite old and not realy recommendable), but use an alternative like described in this answer.

Tobias
  • 2,547
  • 3
  • 14
  • 29
  • Found relevant info here: https://stackoverflow.com/questions/5419039/is-djava-library-path-equivalent-to-system-setpropertyjava-library-path luyifan answer worked for me. – David D Jul 05 '19 at 16:23