我试图在我的Raspberry PI(https://github.com/scream3r/java-simple-serial-connector)上安装一个Java串行通信库,所以我将.so文件(src / java / libs / linux / libjSSC-2.8_armhf.so)复制到了我的库中路径(usr / lib / jvm / java-1.11.0-openjdk-armhf / lib)。
然后,当我测试lib代码示例时:
import jssc.SerialPortList;
public class Main {
public static void main(String[] args) {
String[] portNames = SerialPortList.getPortNames();
for(int i = 0; i < portNames.length; i++){
System.out.println(portNames[i]);
}
}
}
我收到很多错误,指出找不到SerialPortList。
所以我想知道如何正确安装lib。 错误:
javac Main.java
Main.java:1: error: package jssc does not exist
import jssc.SerialPortList;
^
./SerialPortList.java:38: error: cannot find symbol
private static SerialNativeInterface serialInterface;
^
symbol: class SerialNativeInterface
location: class SerialPortList
Main.java:6: error: cannot access SerialPortList
String[] portNames = SerialPortList.getPortNames();
^
bad source file: ./SerialPortList.java
file does not contain class SerialPortList
Please remove or make sure it appears in the correct subdirectory of the
sourcepath.
./SerialPortList.java:43: error: cannot find symbol
serialInterface = new SerialNativeInterface();
^
symbol: class SerialNativeInterface
location: class SerialPortList
./SerialPortList.java:44: error: cannot find symbol
switch (SerialNativeInterface.getOsType()) {
^
symbol: variable SerialNativeInterface
location: class SerialPortList
./SerialPortList.java:45: error: cannot find symbol
case SerialNativeInterface.OS_LINUX: {
^
symbol: variable SerialNativeInterface
location: class SerialPortList
./SerialPortList.java:50: error: cannot find symbol
case SerialNativeInterface.OS_SOLARIS: {
^
symbol: variable SerialNativeInterface
location: class SerialPortList
./SerialPortList.java:55: error: cannot find symbol
case SerialNativeInterface.OS_MAC_OS_X: {
^
symbol: variable SerialNativeInterface
location: class SerialPortList
./SerialPortList.java:60: error: cannot find symbol
case SerialNativeInterface.OS_WINDOWS: {
^
symbol: variable SerialNativeInterface
location: class SerialPortList
./SerialPortList.java:293: error: cannot find symbol
if(SerialNativeInterface.getOsType() ==
SerialNativeInterface.OS_WINDOWS){
^
symbol: variable SerialNativeInterface
location: class SerialPortList
./SerialPortList.java:293: error: cannot find symbol
if(SerialNativeInterface.getOsType() ==
SerialNativeInterface.OS_WINDOWS){
^
symbol: variable SerialNativeInterface
location: class SerialPortList
./SerialPortList.java:334: error: cannot find symbol
if(portHandle < 0 && portHandle !=
SerialNativeInterface.ERR_PORT_BUSY){
^
symbol: variable SerialNativeInterface
location: class SerialPortList
./SerialPortList.java:337: error: cannot find symbol
else if(portHandle !=
SerialNativeInterface.ERR_PORT_BUSY) {
^
symbol: variable SerialNativeInterface
location: class SerialPortList
13 errors
谢谢。
答案 0 :(得分:0)
您需要将您的库添加为外部库。
检查如何在您的IDE上进行操作:Intellij
编辑以匹配OP的IDE:
Geany Tutorial用于外部库。
右键单击需要该库的项目的名称-> 属性->“项目属性”窗口打开。在类别树中 选择“库”节点->在“项目属性”的右侧 窗口中按“添加JAR /文件夹”按钮->选择所需的jar。