Go Down

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

harlandraka94

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,
Alex

lesto

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:
http://blog.cedarsoft.com/2010/11/setting-java-library-path-programmatically/


for the native actually i can't find a good snippet, i'll post mine when i'll be back home
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

lesto

#2
Jun 18, 2012, 10:07 pm Last Edit: Jun 18, 2012, 10:09 pm by lesto Reason: 1
found!
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
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview