问题摘要
当我试图在桌面上编码并将其远程部署到我的Pi上时,我得到了一个类路径错误。
背景
Pi4J v2.0在这里输入链接描述库提供了一个Maven原型以帮助在远程PC上进行开发和说明。
环境
IDE: Intellij Ultimate
Development PC is Windows 10
Java 11.0.2
Maven 3.8.3
Rasp Pi Zero W
Open jdk java 11.0.8
Maven 3.8.3迄今采取的步骤
在开发PC上,我已经安装了原型per:
INSTALL ARCHETYPE
cd pi4j-maven-archetype-master
mvn install
...
BUILD SUCCESS
CREATE PROJECT
mkdir pitest2
mvn archetype:generate -DarchetypeCatalog=local
....
answer questions per instructions
BUILD SUCCESS然后,我用Intellij打开这个项目,用maven刷新它,并将raspberry.properties编辑到我的pi IP地址和登录。
在构建和部署原型附带的示例代码时,说明声明如下:
The project declares in the pom.xml the following maven/ant goals that you can execute with the command shown :
mvn clean : delete all compiled files from local and remote project
mvn install : builds the project, uploads the required jars to the remote target RPI board
mvn antrun:run@exec : runs the program on the remote target
mvn antrun:run@debug : runs a remote debugging session on the target RPI.命令mvn install工作,一个文件被复制到Pi中。
当我尝试使用mvn antrun:run@exec命令时,结果是:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.818 s
[INFO] Finished at: 2021-11-16T20:15:56+13:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:3.0.0:run (exec) on project pitest2: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] C:\Users\RM\IdeaProjects\pitest2\antrun\build.xml:166: The following error occurred while executing this line:
[ERROR] C:\Users\RM\IdeaProjects\pitest2\antrun\build.xml:123: Remote command failed with exit status 1
[ERROR] around Ant part ...<ant antfile="antrun/build.xml" target="run-remote" />... @ 9:59 in C:\Users\RM\IdeaProjects\pitest2\target\antrun\build-main.xml
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException采取的其他步骤
部署的输出显示,pitest.jar与其依赖项被复制到Pi中。
pi@raspberrypi: ls
pi4j-core.jar
pi4j-library-pigpio.jar
pi4j-plugin-pigpio.jar
pi4j-plugin-raspberrypi.jar
pitest2.jar
pitest2-jar-with-dependencies.jar
slf4j-api.jar
slf4j-simple.jar在pi上直接执行的其他尝试:
pi@raspberrypi:~/IdeaProjects/pitest2/dist/lib $ java -cp . pitest2.jar
Error: Could not find or load main class pitest2.jar
Caused by: java.lang.ClassNotFoundException: pitest2.jar
pi@raspberrypi:~/IdeaProjects/pitest2/dist/lib $ java -cp . pitest2.jar com.geekhelp.Main
Error: Could not find or load main class pitest2.jar
Caused by: java.lang.ClassNotFoundException: pitest2.jar
pi@raspberrypi:~/IdeaProjects/pitest2/dist/lib $ java -cp ./ pitest2.jar com.geekhelp.Main
Error: Could not find or load main class pitest2.jar
Caused by: java.lang.ClassNotFoundException: pitest2.jar
pi@raspberrypi:~/IdeaProjects/pitest2/dist/lib $ java -cp pitest2.jar com.geekhelp.Main
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/util/Console
at com.geekhelp.Main.<clinit>(Main.java:24)
Caused by: java.lang.ClassNotFoundException: com.pi4j.util.Console
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
pi@raspberrypi:~/IdeaProjects/pitest2/dist/lib $在/dist下似乎是个胖罐子
pi@raspberrypi:~/IdeaProjects/pitest2/dist $ java -cp pitest2.jar com.geekhelp.Main
21:01:58 [main] INFO com.pi4j.util.Console - ---------------------------
21:01:58 [main] INFO com.pi4j.util.Console - | Hello Rasbian world ! |
21:01:58 [main] INFO com.pi4j.util.Console - ---------------------------
21:01:58 [main] INFO com.pi4j.Pi4J - New auto context
21:01:58 [main] INFO com.pi4j.Pi4J - New context builder
...
...
21:02:02 [main] DEBUG com.pi4j.platform.impl.DefaultRuntimePlatforms - platforms loaded [1]
21:02:02 [main] DEBUG com.pi4j.runtime.impl.DefaultRuntime - Pi4J context/runtime successfully initialized.'
21:02:02 [main] DEBUG com.pi4j.context.impl.DefaultContext - Pi4J runtime context successfully created & initialized.'
21:02:02 [main] DEBUG com.pi4j.context.impl.DefaultContextBuilder - Pi4J successfully created and initialized a new runtime 'Context'.'
21:02:02 [main] INFO com.pi4j.util.Console - --------------------
21:02:02 [main] INFO com.pi4j.util.Console - | Pi4J PLATFORMS |
21:02:02 [main] INFO com.pi4j.util.Console - --------------------
21:02:02 [main] INFO com.pi4j.util.Console -
PLATFORMS: [1] "Pi4J Runtime Platforms" <com.pi4j.platform.impl.DefaultPlatforms>
└─PLATFORM: "RaspberryPi Platform" {raspberrypi} <com.pi4j.plugin.raspberrypi.platform.RaspberryPiPlatform> {Pi4J Platform for the RaspberryPi series of products.}
21:02:03 [main] INFO com.pi4j.util.Console -
com.pi4j.provider.exception.ProviderNotFoundException: Pi4J provider [pigpio-digital-output] could not be found. Please include this 'provider' JAR in the classpath.
at com.pi4j.provider.impl.DefaultRuntimeProviders.get(DefaultRuntimeProviders.java:238)
at com.pi4j.provider.impl.DefaultProviders.get(DefaultProviders.java:147)
at com.pi4j.provider.Providers.get(Providers.java:253)
at com.pi4j.context.Context.create(Context.java:316)
at com.pi4j.internal.IOCreator.create(IOCreator.java:58)
at com.pi4j.internal.IOCreator.create(IOCreator.java:96)
at com.pi4j.internal.IOCreator.create(IOCreator.java:176)
at com.geekhelp.Main.run(Main.java:63)
at com.geekhelp.Main.main(Main.java:34)
21:02:03 [main] DEBUG com.pi4j.platform.impl.DefaultRuntimePlatforms - removed platform from managed platform map [id=raspberrypi; name=RaspberryPi Platform; class=com.pi4j.plugin.raspberrypi.platform.RaspberryPiPlatform]一个合作伙伴已经从GitHub下载了我的项目(它与原型没有变化),并成功地在Rasp 4(不是零W)上运行它。
问:为什么代码看不到依赖项?什么时候跑?
发布于 2021-11-16 20:21:51
我设法修好了。
Pi的问题是,常用的Java的默认版本是一个不受支持的ARM错误。因此,我按照下面的说明安装了祖鲁版本:
https://webtechie.be/post/2020-08-27-azul-zulu-java-11-and-gluon-javafx-11-on-armv6-raspberry-pi/
当从我的桌面IDE进行远程执行时,rasperberry.properties文件的值指向/usr/lib/jvm/default下的default-java文件夹,但是zulu版本的Java并不创建这个文件夹。
对我来说,修复方法是在rasperberry.properties中更改以下行:
#target.remote.jre=/usr/lib/jvm/default-javam #COMMENT OUT THIS LINE
target.remote.jre=/usr/lib/jvm/zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf #PUT YOUR JAVA PATH HEREhttps://stackoverflow.com/questions/69985205
复制相似问题