我想在我的Raspberry Pi 3上使用XBee Java Lib及其教程做一個簡單的Xbee示例,但我想在將它轉換爲.jar文件之前執行它。我只想將它作爲一個.class文件來執行,非常簡單,之後我想將它導入到另一個項目中。 (我不擅長與Java,因爲它是可以看到) 編譯我試圖執行它之後:在樹莓派上使用Java Lib的XBee
java -cp $XBJL_CLASS_PATH:. com.digi.xbee.example.MainApp
我echo $XBJL_CLASS_PATH
是:
libs/xbee-java-library-1.2.1.jar:libs/rxtx-2.2.jar:libs/slf4j-api-1.7.12.jar:libs/slf4j-nop-1.7.12.jar:libs/android-sdk-5.1.1.jar:libs/android-sdk-addon-3.jar
這意味着所有的.jar繳費至從XBee Java Lib中使用。
它沒有work.I've也嘗試過:
java com.digi.xbee.example.MainApp
我總是得到同樣的錯誤:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/digi/xbee/api/XBeeDevice
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.digi.xbee.api.XBeeDevice
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
有誰知道什麼可以happenning?這是說我沒有導入XBeeDevice,我導入了libs/xbee-java-library-1.2.1.jar
。
PS:代碼啓動與此:
package com.digi.xbee.example;
import com.digi.xbee.api.WiFiDevice;
import com.digi.xbee.api.XBeeDevice;
import com.digi.xbee.api.exceptions.XBeeException;
import com.digi.xbee.api.models.XBeeProtocol;
public class MainApp {
/* Constants */
// TODO Replace with the port where your sender module is connected to.
private static final String PORT = "/dev/ttyAMA0/";
// TODO Replace with the baud rate of your sender module.
private static final int BAUD_RATE = 9600;
private static final String DATA_TO_SEND = "Hello XBee World!";
public static void main(String[] args) {
XBeeDevice myDevice = new XBeeDevice(PORT, BAUD_RATE);
byte[] dataToSend = DATA_TO_SEND.getBytes();
try {
myDevice.open();
System.out.format("Sending broadcast data: '%s'", new String(dataToSend));
if (myDevice.getXBeeProtocol() == XBeeProtocol.XBEE_WIFI) {
myDevice.close();
myDevice = new WiFiDevice(PORT, BAUD_RATE);
myDevice.open();
((WiFiDevice)myDevice).sendBroadcastIPData(0x2616, dataToSend);
} else
myDevice.sendBroadcastData(dataToSend);
System.out.println(" >> Success");
} catch (Exception e) {
System.out.println(" >> Error");
e.printStackTrace();
System.exit(1);
}
finally {
myDevice.close();
}
}
}
在此先感謝。