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