Running .class file built from command line

Hi all Processing folks, I am having trouble running .class file on command line. Since I want to run my sketch in headless mode on a Mac, I followed this solution ( to build my sketch.

So basically, say helloWorld.pde is the name of my sketch and the sketch is stored in folder helloWorld, on Terminal, I ran “processing-java --sketch=/Users/xxx/helloWorld --output=/Users/xxx/helloWorld_output --build”. This generates a .class file in folder helloWorld_output, but I couldn’t run the .class file when I do “java -cp . helloWorld” or “java helloWorld” or even “java -cp /Users/xxx/helloWorld_output helloWorld”.

I am using Processing 3 and I also downloaded Java 10 for command line tools. I have read that Java 10 is not compatible with Processing 3 but I am not sure if this is the issue on Terminal.

Please help me if you have encountered a similar issue before. :slight_smile:

Forgot to mention the error it gives -
Error: Could not find or load main class helloWorld
Caused by: java.lang.NoClassDefFoundError: processing/core/PApplet


Dunno. Maybe turn your “.class” into a “.jar” file? :thinking:

Hi GoToLoop, how would I do that?

I did it once when I compiled my “.java” file using javac; and then used jar to get a “.jar” outta the resultant “.class” file. :grinning:

However, I don’t remember exactly how I did it. I’ve read some articles in order to do it. :open_book:

You may start your search here I guess: :relieved:

Not sure if this helps, here is the wiki for headless mode: Running witout a dispaly.

Related to running code, could you export your application? In Windows the operation generates and executable. I just tested this in Linux and it works the same way. You need to go into one of those generated folders and find the executable which will have the same name as the name of your sketch.

Related to your error Caused by: java.lang.NoClassDefFoundError: processing/core/PApplet, I would recommend you copy the core.jar file into your a folder named code and place this folder within your sketch folder. This is not the best way to do this but it should work as it will ensure you have access to the Processing definition in core.jar. Notice this assumes you are not using any other contributed library or external resources aka other jars. Do this if exporting your application doesn’t work for you.


Hi there, thanks for your help! Unfortunately I’m using a mac mini and since the article is in Linux it is not helpful :confused: Running in exported executable also does not work…

I would love to try the method u suggested, but I’m also using contributed libraries in my sketch - how would I be able to link that?


Hi Ellen,
Unfortunately I do not have a mac to test or provide any other advice. I would think that mac should work the same way as a Linux OS, as they are essentially the same thing. One thing you need to make sure is that the file has the proper ownership and it has the executable flag. In a console, you should go to the directory containing the executable file and type ls -la and it should tell you if you have the x attribute set for the current user (as a minimum). If this is not clear, please paste the line related to your executable file produced when you execute the ls -la command.

Not sure why that wouldn’t work. Maybe because you are running in headless mode? Add a println in setup and see if you get data in the console when you execute the program.

Related to other contributed libraries, I can only suggest to copy the jar of those libraries in the folder named code which should be created by you (if you don’t have it) and it should be place within your sketch folder, at the same level as the data folder. However, I am not 100% sure you need to do this as I’ think processing-java should be able to find those libraries, if you are calling this function within the sketch folder when building your code. However, I do not use this command line feature of Processing that often… so I am not sure about the mechanics under the hood.


For what it’s worth… I was running Processing headless on a Raspberry Pi and had a similar question. It turned out to be easier to just use --export, but to answer your question:

Edit the processing-java script to enable logging and look at the class path it builds up, which contains all of the Processing JAR files. To this you also need to append the path of your sketch’s .class file, the same path you passed as the --output directory.

However if you try to call save() or similar, you’ll want to use an absolute path. I tried setting user.dir which is the property from which the sketch path is derived but it did not work.

1 Like