0

PROBLEM SUMMARY

I am getting a class path error when I try to code on my desktop and deploy it remotely to my Pi Zero W.

BACKGROUND

The Pi4J v2.0enter link description here library provides a Maven Archetype to help with Development and instructions for developing on a remote PC.

ENVIROMENT

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

STEPS TAKEN SO FAR

On development PC I have installed the Archetype 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

Then I open the project in Intellij and refresh it with maven and edit the raspberry.properties to my pi IP address and login.

When building and deploying the sample code included with Archetype the instructions state:

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.

The command mvn install works and a file is copied to Pi.

When I attempt the mvn antrun:run@exec command results in:

[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

OTHER STEPS TAKEN

The output from the deploy shows that the pitest.jar is copied to the Pi with its dependencies.

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

Other attempts to execute on the pi directly:

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 $

And what appears to be a fat jar under /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]

A associate has downloaded my project from GitHub (which is unchanged from the Archetype) and run it successfully on a Rasp Pi 4 (not Zero W).

Q: Why is the code not seeing the dependencies? when run?

Radika Moonesinghe
  • 361
  • 2
  • 6
  • 17

1 Answers1

1

I managed to fix it.

The issue with the Pi Zero W is that the default version of Java JDK that is commonly used was giving an unsupported ARM error. So I installed the Zulu version as per the instruction's here :

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

When doing remote execution from my desktop IDE the rasperberry.properties file has a value that points to default-java folder under /usr/lib/jvm/default-java but the zulu version of Java JDK I installed doesn't create this folder.

The fix for me was to change the following line in 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
Radika Moonesinghe
  • 361
  • 2
  • 6
  • 17