问题描述:

I am trying to run a jar file that is using pi4j.

sudo java -classpath /opt/pi4j/lib/pi4j-core.jar -jar Test.jar test.Main

Problem is I keep getting this error

Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/io/gpio/GpioFactory

at test.Main.main(Main.java:11)

Caused by: java.lang.ClassNotFoundException: com.pi4j.io.gpio.GpioFactory

at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 1 more

I don't see why the link isn't being made properly.

网友答案:

I have never done it in command line. But this worked for me: in IntelliJ, I added the pi4J jar files to my project as modules. I then made an artifact and got IntelliJ to create a jar file for me (with all the dependencies including pi4J). Then I transferred the jar file to the pi and it ran fine.

相关阅读:
Top