Trying to set lib path in code for RXTX in java on Pi

问题: 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...

问题:

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.


回答1:

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.

  • 发表于 2019-07-06 21:55
  • 阅读 ( 147 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除