I have an existing application which normally communicates with it's target over TCP, however new requirements state that the connection may also be made over a serial COM port.
The application as it stands is wholly self-contained, in that is it a single jar file which the end user can copy where it might be needed, and double click to launch.
It seems that RXTX breaks this model, as it requires additional DLL or SO native plugins to be included on the library path; if it is not possible to communicate with Serial ports using native Java, how can I package my application (using ,aven) such that RXTX will be available at runtime, by simply double clicking the Jar file.
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path: [__CLASSPATH__] thrown while loading gnu.io.RXTXCommDriver
You need to package the library into your jar file, then extract it, writing it out as a file, then load it (
importstatements and exception/error handling omitted):Note that you'll need to add versions of your library for every OS and architecture you support. That includes both 32- and 64-bit versions, because it's quite possible to run a 32-bit JVM on a 64-bit OS.
You can use the
os.archsystem property to identify if you're running in a 64-bit JVM. If the property has the string"64"in it, you're running in a 64-bit JVM. It's pretty safe to assume it's a 32-bit JVM otherwise:You might also have to use
YourClass.class.getClassLoader().getResourceAsStream()if you're customizing your class loader(s).Watch out for OS and CPU compatibility. You need to compile your libraries so they run on older OS versions and older CPUs. If you build on Centos 7 on a new CPU, someone who tries to run on Centos 6 or an older CPU will have problems. You don't want your product crashing on the user because your library got a
SIGILLsignal for an illegal instruction. I'd recommend building the libraries on VMs where you can control the build environment - create VMs using older CPU models and install old OS versions on them.You also need to watch out for Linux systems that mount
/tmpwithnoexec. That or some SE Linux settings might cause the shared object load to fail.