Compiling and executing a Processing sketch as a Java class

Processing sketches (PDEs) are translated from the processing syntax to pure Java and are compiled and packaged into executable JARs. Is it possible to by pass the packaging step and go straight from the Java code to your own compiled class? Yes it is!

NOTE: Apart from your source and compiled class file, you will need the Processing “core.jar” binary to compile the class as well as run it.

Steps:

  1. Use Processing to create a sketch file (.pde) and use the “Export” capability to export it to your native enviornment
  2. Open the generated export folder and navigate to the “source” directory. Inside here you will find the Java source file
  3. Compile the Java source file via: javac -cp "core.jar" SOURCE_FILE.java
  4. Run the compiled class via the following command: java -cp "core.jar:." CLASS_FILE
Advertisements

3 thoughts on “Compiling and executing a Processing sketch as a Java class

  1. I read a lot of interesting posts here. Probably you spend a lot of
    time writing, i know how to save you a lot of work, there is an online tool that creates unique, google friendly posts
    in minutes, just type in google – rewriter creates
    an unique article in a minute

  2. Hello Rishi, I am trying to get a processing sketch compiled but it just won’t work. I’m not that good with programming etc, sorry!

    What I did so far:
    1. Open the processing sketch (it’s called hrmi_simple.pde)
    2. Export it
    3. Go to the folder that was created (there are files called “core.jar”, “hrmi_simple.jar”, “hrmi_simple.java”, “hrmi_simple.pde”, “index.html”, “loading.gif”, “RXTXcomm.jar” and “serial.jar”)
    4. From here I have no idea what to do… What is the “source directory”. And how do I do the actual compiling???

    Thanks for the help!
    Regards from Germany, Samuel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s