gpt4 book ai didi

java - 在 Raspberry 上导入 java lib

转载 作者:行者123 更新时间:2023-12-02 01:28:04 25 4
gpt4 key购买 nike

我尝试在我的 Raspberry PI ( https://github.com/scream3r/java-simple-serial-connector ) 上安装 java 串行通信库,因此我将 .so 文件 (src/java/libs/linux/libjSSC-2.8_armhf.so) 复制到我的 lib 路径 ( 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。

所以我想知道如何正确安装该库。错误:

 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

谢谢。

最佳答案

您需要将您的库添加为外部库。
检查如何在 IDE 上执行此操作:Intellij 的示例

编辑以匹配 OP 的 IDE:
Geany Tutorial对于外部库。

Right-click on the name of the project that needs the library -> Properties -> The Project Properties window opens. In Categories tree select “Libraries” node -> On the right side of the Project Properties window press button “Add JAR/Folder” -> Select jars you need.

关于java - 在 Raspberry 上导入 java lib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57569595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com