尝试运行我的Java程序时收到这些错误

Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/io/gpio/GpioFactory
        at FileWatch.main(FileWatch.java:53)
Caused by: java.lang.ClassNotFoundException: com.pi4j.io.gpio.GpioFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more


这是我的代码,

public class FileWatch {

        static String clkID;
        static String clkID2;
        static String ts;
        static String ts1;
        static boolean done = false;
        static boolean REdone = false;
        static boolean finished = false;
        static boolean ready;

        static String host ="jdbc:mysql://localhost/dancers";
        static String username ="root";
        static String password ="beaker19";


        public static void main(String[] args) throws IOException,
                        InterruptedException {

       // create gpio controller
        final GpioController gpio = GpioFactory.getInstance();

        // provision gpio pin #01 as an output pin and turn on
        final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "MyLED", PinState.HIGH);


                while (true) {
                        done = false;
                        REdone=false;
                        checkFile();
                        pin.high();
                        Thread.sleep(3000);
                        REcheckFile();
                        Thread.sleep(500);
                        //Thread.
                        if (clkID.equals(clkID2)) {

                        uploadTimes();

                        }

                        else {
                                System.out.println("Wrong matching ID's");
                        }
                        Thread.sleep(1000);
                        pin.low();
                 }
}


我从来没有和pi4j合作过,所以我不知道我要去哪里错了!
这似乎是gpiofactory类的问题,但我尚未对其进行任何更改,并且不确定从互联网上可以读取的内容是什么,这是导入软件包的问题...

我已经这样编译了:

pi@raspberrypi ~/rpi2ardu $ javac -cp .:mysql-connector-java-3.1.1.jar:/opt/pi4j/lib/'*' FileWatch.java

最佳答案

我解决了同样的问题。

查找您的应用清单文件。默认情况下创建一个,位于源代码树=>META-INF=>MANIFEST.MF

只需在其中添加一个类路径,即pi4j JAR文件所在的位置,它应如下所示:

{
    Manifest-Version: 1.0
    Main-Class: yourclassname.Main
    Class-Path: /opt/pi4j/lib/pi4j-core.jar /opt/pi4j/lib/pi4j-device.jar /opt/pi4j/lib/pi4j-gpio-extension.jar /opt/pi4j/lib/pi4j-service.jar
}


生成文件,执行它。

10-06 13:47