我正在尝试为使用 Pi4j 的覆盆子 pi 的 java 创建此步进电机控制器的驱动程序,但在尝试运行项目的已编译 jar 后我不断收到此错误(当它未在运行的 .jar 中编译时)。我尝试了这篇文章的答案,但是当我尝试执行清单解决方案时(在下面查看该文件的外观),我在 MF 文件中添加了清单文件,resources/META-INF/MANIFEST.MF
我在 MF 文件中遇到了这个错误,':' expected
我真的很困惑如何解决这个问题所以请像我五岁一样向我解释,如果有什么我应该修复的(我正在使用 maven)这可能是我编译我的应用程序的方式吗?我编程的方式?我不应该使用 pi4j 并使用替代方案吗?
终端
myName@Macbook-Air target % java -cp A4988Driver-1.1-SNAPSHOT.jar Controller.Debug
Something should print
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/io/gpio/GpioFactory
at Controller.Motor.<init>(Motor.java:11)
at Controller.Debug.main(Debug.java:9)
Caused by: java.lang.ClassNotFoundException: com.pi4j.io.gpio.GpioFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 2 more
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>A4988Driver</artifactId>
<version>1.2-BETA</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
</dependencies>
</project>
电机.java
package Controller;
import com.pi4j.io.gpio.*;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
public class Motor{
public boolean motorGo;
private static GpioPinDigitalOutput Ms1, Ms2, Ms3, Relay, Dir;
GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalInput btnPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);;
public void rotate(boolean clockwise, boolean ms1, boolean ms2, boolean ms3, Pin relay, Pin MS1, Pin MS2, Pin MS3, Pin DIR, long stepDelay) throws InterruptedException {
if(Ms1 == null || Ms2 == null || Ms3 == null || Relay == null){
Relay = gpio.provisionDigitalOutputPin(relay, "relay", PinState.HIGH);
Ms1 = gpio.provisionDigitalOutputPin(MS1, "ms1", PinState.LOW);
Ms2 = gpio.provisionDigitalOutputPin(MS2, "ms2", PinState.LOW);
Ms3 = gpio.provisionDigitalOutputPin(MS3, "ms3", PinState.LOW);
Dir = gpio.provisionDigitalOutputPin(DIR, "DIR", PinState.LOW);
}
if(clockwise) Dir.high();
else Dir.low();
if(ms1) Ms1.high();
else Ms1.low();
if(ms2) Ms2.high();
else Ms2.low();
if(ms3) Ms3.high();
else Ms3.low();
btnPin.setShutdownOptions(true);
motorGo = true;
btnPin.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent gpioPinDigitalStateChangeEvent) {
motorGo = false;
}
});
while(motorGo){
Relay.low();
Thread.sleep(stepDelay);
Relay.high();
}
}
}
Debug.java(我在测试应用程序时运行的)
package Controller;
import com.pi4j.io.gpio.RaspiPin;
public class Debug {
public static void main(String[] args) throws InterruptedException {
System.out.println("Something should print");
Motor motor = new Motor();
motor.rotate(true, true, true, true, RaspiPin.GPIO_21, RaspiPin.GPIO_16, RaspiPin.GPIO_19, RaspiPin.GPIO_20, RaspiPin.GPIO_26, (long) 0.005);
}
}