私は arduino で遊んで、それを Java とインターフェースし始めました。それはかなり簡単でしたが、今は librxtxSerial ネイティブ ライブラリをプログラムでロードしたいのですが、わかりません。私は MacOS 64 ビットで Java6 を使用しているので、次の jnilib を使用しました: http://blog.iharder.net/2009/08/18/rxtx-java-6-and-librxtxserial-jnilib-on-intel-mac-ここで推奨されるos-x/ : http://arduino.cc/playground/Interfacing/Java
その後、次のようにプログラムでロードしようとしました:
/**
* Loads the jnilib
*/
public static void loadJniLib() {
// loads the jnilib from the source folder "src/main/resources"
URL url = Demo.class.getResource("/librxtxSerial.jnilib");
try {
System.load(url.getPath());
}
catch (UnsatisfiedLinkError unsatisfiedLinkError) {
// native code library failed to load.
unsatisfiedLinkError.printStackTrace();
}
}
これはうまくいくようです(少なくとも例外はスローされません)。
しかし、私が呼び出すとCommPortIdentifier.getPortIdentifier(PORT_NAME);
、次の例外がスローされます。
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
at fr.free.mdwhatever.arduino.maven.Demo.initialize(Demo.java:57)
at fr.free.mdwhatever.arduino.maven.Demo.main(Demo.java:102)
http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#load ( java.lang.String)
何か案が?
PS : コード全体をここで見つけることができます: https://gist.github.com/1853637 rxtx jar がクラスパスにあり、ネイティブ ライブラリの場所が定義されている場合に機能します (Eclipse の場合: http://www. eclipsezone.com/eclipse/forums/t49342.html )