1

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.

6
  • 1
    Try java -cp lib/core.jar:. Main.MySketch Commented May 14, 2024 at 15:36
  • Same error Error: Could not find or load main class Main.MySketch Caused by: java.lang.NoClassDefFoundError: processing/core/PApplet Commented May 14, 2024 at 15:40
  • 1
    In that case, your current directory must no longer contain directory lib Commented May 14, 2024 at 15:43
  • Moving the lib directory up a level worked. Thank you, still getting the hang of directory setups. Commented May 14, 2024 at 15:46
  • 1
    Actually, looking more closely at your compilation command, what should have been the command is java -cp lib/core.jar:src Main.MySketch But the unfortunate thing there is that you're mixing up your source with binaries. Package names should be lower case in Java though, and class names start upper case Commented May 14, 2024 at 15:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.