[英]Java library import difficulty
I'm trying to compile a small test program I have written for a raspberry pi. 我正在尝试编写一个我为树莓派写的小测试程序。 The program makes use of the Pi4J library to control the piface add-on board.
该程序利用Pi4J库来控制piface附加板。
What I have done so far is based on the following tutorial: http://www.savagehomeautomation.com/piface 到目前为止,我所做的工作基于以下教程: http : //www.savagehomeautomation.com/piface
While I can get the above example program to compile within my IDE after setting up the class paths I get compile errors with the one I have made and as far as I can tell the imports are set up in the same way. 虽然我可以在设置类路径后在我的IDE中编译上面的示例程序,但我得到的编译错误与我所做的一样,据我所知,导入设置方式相同。
It says that each of the following packages does not exist: 它表示以下每个包都不存在:
import java.io.IOException;
import com.pi4j.component.switches.SwitchListener;
import com.pi4j.component.switches.SwitchState;
import com.pi4j.component.switches.SwitchStateChangeEvent;
import com.pi4j.device.piface.PiFace;
import com.pi4j.device.piface.PiFaceLed;
import com.pi4j.device.piface.PiFaceRelay;
import com.pi4j.device.piface.PiFaceSwitch;
import com.pi4j.device.piface.impl.PiFaceDevice;
import com.pi4j.wiringpi.Spi;
I'm assuming that my problem is relatively simple but I don't really understand how import statements work and it's quite vague topic to search about. 我假设我的问题相对简单但我并不真正理解导入语句的工作方式,而且搜索的主题非常模糊。 I have included some file paths if that helps.
如果有帮助,我已经包含了一些文件路径。
This is where my project resides: 这是我的项目所在的位置:
/home/pi/JBerries/relay
and this is where the pi4j library is: 这就是pi4j库的地方:
/opt/pi4j
I hope the following image provides some of the information requested, note that the class paths are already set up: 我希望下面的图片提供了一些请求的信息,请注意类路径已经设置:
You need to set the CLASSPATH environment variable to /opt/pi4j or the jar file therein. 您需要将CLASSPATH环境变量设置为/ opt / pi4j或其中的jar文件。 WIthout this the compiler is unable to know where your libary is located and will give you the errors you describe.
但是,编译器无法知道您的库所在的位置,并且会向您提供您描述的错误。
If you're using a project in JBerries you need to configure the classpath for the project - the screenshot shows the classpath for single-file compilations only. 如果您在JBerries中使用项目,则需要为项目配置类路径 - 屏幕截图仅显示单文件编译的类路径。 To edit the project config right-click the root node in the project window and select properties.
要编辑项目配置,请右键单击项目窗口中的根节点,然后选择属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.