有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Pi4J类路径错误Intellij在Pi Zero W上远程运行

问题摘要

当我试图在桌面上编写代码并将其远程部署到我的PiZero W时,我遇到了一个类路径错误

背景

{a1}v2。0enter link description here库提供了一个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上,我已根据安装了原型:

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刷新它并编辑树莓。属性设置为我的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

采取的其他步骤

deploy的输出显示最简单的。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 Pi 4(不是零W)上成功运行了它

问:为什么代码没有看到依赖项?什么时候跑


共 (1) 个答案

  1. # 1 楼答案

    我设法把它修好了

    PiZero W的问题在于,常用的Java JDK的默认版本给出了一个不受支持的ARM错误。因此,我按照此处的说明安装了Zulu版本:

    https://webtechie.be/post/2020-08-27-azul-zulu-java-11-and-gluon-javafx-11-on-armv6-raspberry-pi/

    从我的桌面IDE执行远程执行时,请使用rasperberry。属性文件的值指向/usr/lib/jvm/default java下的默认java文件夹,但我安装的javajdk的zulu版本没有创建此文件夹

    我的解决办法是更改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 HERE