how to set rxtx with OSGi Equinox?

随声附和 提交于 2019-12-11 07:43:55

问题


I am looking for a solution to my problem.
I am developing a bundle that has to read from the serial port by means of rxtx jar.
When I launch the application, I get the following error

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:123)
    at ez430.Port.<init>(Port.java:29)

I have added the jar to build path and set it in the jVM.

Please help me!!


回答1:


Since OSGi is multi-platform and needs to take care of appearing and disappearing bundles, the handling of native libraries (as rxtx does) needs to be explicitly specified for a bundle. That is done using a Bundle-NativeCode header in the bundle that includes the rxtx jar file. The native library to load can be indicated per os and architecture. In this case it may look like:

Bundle-NativeCode: lib/Linux/x86_64-unknown-linux-gnu/librxtxSerial.so; 
  osname="Linux";processor="x86-64",
  lib/Windows/i368-mingw32/rxtxSerial.dll;
  osname="Windows"

The above example indicates that for Linux x86-64 the library can be found in lib/Linux/x86_64-unknown-linux-gnu/librxtxSerial.so and for Windows (all architectures) in lib/Windows/i368-mingw32/rxtxSerial.dll. Paths are relative in the bundle, therefore don't forget to include the shared libraries in your bundle.

For further details, look in the OSGi core specification.



来源:https://stackoverflow.com/questions/26739459/how-to-set-rxtx-with-osgi-equinox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!