Go Down

Topic: Java Serial Communication libraries (Read 780 times) previous topic - next topic


Hi all, i'm using Arduino since June 2011, now i built a Java program which can communicate with it. Everithing works perfectly.
To use rxtxSerial library i MUST place it in the java folder, i placed everithing in this folder and it works.
The fact is: i have to make my program work on ANY computer without having to place libraries in the Java folder, also because with new security rules in the newest Operating Systems i need to have permissions to access the programs folder.
So is there a way to load these libraries at runtime without placing them in the Java folder? i tried with System.load() and System.loadLibrary(), the path is correct, i verified it, but it does not work, it says "No suitable RXTXSerial found in java PATH"... Any suggestions?

Thanks in advance,


you need to load 2 file: the .jar, taht is always the same for every os, AND the native, that vary based on witch OS you are using.

if you look on the internet you'll find many overcomplicated (and obsolete) solution.

normally for library path, a .sh (linux/mac) or a .bat is created, but youcan set it inside your program:

for the native actually i can't find a good snippet, i'll post mine when i'll be back home
Guida per principianti http://playground.arduino.cc/Italiano/newbie
Unoffical Telegram group https://t.me/genuino


Jun 18, 2012, 10:07 pm Last Edit: Jun 18, 2012, 10:09 pm by lesto Reason: 1
i use this code to load lwjgl native, but it is practically the same used for RXTX (old code was in the old HDD.. rip)

just be sure to change the path and file name accordantly, and call this method on the constructor of the main class that you'll use for the serial communication.

Code: [Select]
private static void loadNatives() {
Logger staticLog = LoggerFactory.getLogger("Natives Loader");
staticLog.debug("Loading natives");
try {
String osName = System.getProperty("os.name");

staticLog.info("Operating system name => {}", osName);

File path = new File("Libraries" + File.separator + "lwjgl-2.8.3" + File.separator + "native" + File.separator + osName.toLowerCase());

System.setProperty("org.lwjgl.librarypath", path.getAbsolutePath());

} catch (UnsatisfiedLinkError e) {
staticLog.error("Native code library failed to load", e);
staticLog.info("Loaded natives");

uh, and remove logger code if give you error, maybe instead use System.out.println
Guida per principianti http://playground.arduino.cc/Italiano/newbie
Unoffical Telegram group https://t.me/genuino

Go Up