# Running .class file built from command line

**URL:** https://discourse.processing.org/t/running-class-file-built-from-command-line/1719
**Category:** Development
**Created:** [July 12, 2018, 2:30pm UTC](https://discourse.processing.org/t/running-class-file-built-from-command-line/1719 "2018-07-12T14:30:27Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ellenlowing](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ellenlowing](https://discourse.processing.org/u/ellenlowing)
#### Post date: [July 12, 2018, 2:30pm UTC](https://discourse.processing.org/t/running-class-file-built-from-command-line/1719/1 "2018-07-12T14:30:27Z")

</div>

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 ([https://github.com/processing/processing/issues/3996](https://github.com/processing/processing/issues/3996)) 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. 🙂

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

Thanks!  
-Ellen

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [July 12, 2018, 2:33pm UTC](https://discourse.processing.org/t/running-class-file-built-from-command-line/1719/2 "2018-07-12T14:33:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ellenlowing](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ellenlowing](https://discourse.processing.org/u/ellenlowing)
#### Post date: [July 12, 2018, 2:40pm UTC](https://discourse.processing.org/t/running-class-file-built-from-command-line/1719/3 "2018-07-12T14:40:50Z")

</div>

Hi GoToLoop, how would I do that?

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [July 12, 2018, 2:48pm UTC](https://discourse.processing.org/t/running-class-file-built-from-command-line/1719/4 "2018-07-12T14:48:52Z")

</div>

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. 😀

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

You may start your search here I guess: 😌

> **[JAR (file format)](https://en.wikipedia.org/wiki/JAR_(file_format))**
>
> A JAR (Java ARchive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution.
> JAR files are archive files that include a Java-specific manifest file. They are built on the ZIP format and typically have a .jar file extension.
> A JAR file allows Java runtimes to efficiently deploy an entire application, including its classes and their associated resources, in a single request. JAR file elem...

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [July 12, 2018, 8:26pm UTC](https://discourse.processing.org/t/running-class-file-built-from-command-line/1719/5 "2018-07-12T20:26:55Z")

</div>

Not sure if this helps, here is the wiki for [headless mode: Running witout a dispaly](https://github.com/processing/processing/wiki/Running-without-a-Display).

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.

Kf

---

<div class="post-metadata">

### Author: ![ellenlowing](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ellenlowing](https://discourse.processing.org/u/ellenlowing)
#### Post date: [July 12, 2018, 11:19pm UTC](https://discourse.processing.org/t/running-class-file-built-from-command-line/1719/6 "2018-07-12T23:19:04Z")

</div>

Hi there, thanks for your help! Unfortunately I’m using a mac mini and since the article is in Linux it is not helpful 😕 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?

Thanks  
-Ellen

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [July 13, 2018, 2:36am UTC](https://discourse.processing.org/t/running-class-file-built-from-command-line/1719/7 "2018-07-13T02:36:09Z")

</div>

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.

> [@ellenlowing](#):
>
> 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”

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.

Kf

---

<div class="post-metadata">

### Author: ![rgov](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rgov/32/5225_2.png) [@rgov](https://discourse.processing.org/u/rgov)
#### Post date: [May 17, 2019, 10:58pm UTC](https://discourse.processing.org/t/running-class-file-built-from-command-line/1719/8 "2019-05-17T22:58:35Z")

</div>

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.
