I’ve built a simple Java program using some Processing classes, and I’m trying to get them to run from the command line (so I can get them to run on a Raspberry Pi without an IDE). I can get the .java files to compile without issue, but they won’t run without throwing errors.
For context, Java 21, MacOS.
Generally the code looks like this:
package Main;
import processing.core.PApplet;
public class MySketch extends PApplet {
//
public static void main(String[] args) {
String[] processingArgs = {"MySketch"};
MySketch mySketch = new MySketch();
PApplet.runSketch(processingArgs, mySketch);
}
}
I can get the code to compile using
cd (SketchTest folder)
javac -cp lib/core.jar src/Main/*.java
without issue. I run into problems in the next step to run it
First I run
cd SketchTest/src
so I can run the class from the Main package
Then I run with
java Main.MySketch
I get
Error: Could not find or load main class Main.MySketch
Caused by: java.lang.NoClassDefFoundError: processing/core/PApplet
So I assumed it was a classpath issue. I moved the core.jar file into a lib folder in the Main package and ran
java -cp lib/core.jar Main.MySketch
Which gave me
Error: Could not find or load main class Main.MySketch
Caused by: java.lang.ClassNotFoundException: Main.RotTest
I’m not sure why this is giving so much trouble. The Program runs fine from IntelliJ, but I can’t get it to run after compilation.
I don’t have a huge amount of experience in Java, and I’m coming into it out of Processing, so if I’m missing something obvious, please tell me.