How to Build clj-processing
Recently I wrote up a tutorial on getting started programming Processing sketches in Clojure. The clj-processing bindings require a slightly involved build process, which I’m detailing here. I have since created a quick-start project that contains the pre-built binary, so unless you want to build a newer version of the processing.core.jar library, you can use that. So here’s how to build it.
Both are in somewhat early development, so it’s a bit tricky, but here we go.
- Get Clooj by downloading the latest “standalone” jar from the downloads page. That file is the IDE; it doesn’t install, you just double-click on that and it opens the Clooj environment.
- Build the clj-processing core. This is the most complicated part; instructions are for OSX—other OSes have similar commands.
- Clone the repo from github.
- Find your Processing core.jar and OpenGL jars. They will be in (Processing Dir)/core.jar and (Processing Dir)/modes/java/libraries/opengl/library. If you’re on OSX and have Processing in your root Applications folder, (Processing Dir) is this: /Applications/Processing.app/Contents/Resources/Java
- From a terminal (on OSX, assuming you have Processing in your Applications folder):
- From the same terminal, in the clj-processing directory, run
If you don’t have ant, you need to install Java.
- This should build the processing.core.jar. Now open Clooj and make a new project and note where you save it.
- Make a lib/ folder in the root of your Clooj project folder.
- Copy processing.core.jar and Processing’s core.jar file to your Clooj project lib/ folder.
- Restart Clooj. When it opens again, it should say something like this in the output window:
=== RESTARTING /Users/daleth/Projects/Clojure/Test REPL === Classpath: /Users/daleth/Projects/Clojure/Test/lib /Users/daleth/Projects/Clojure/Test/src /Users/daleth/Projects/Clojure/Test/lib/core.jar /Users/daleth/Projects/Clojure/Test/lib/processing.core.jar
- To get OpenGL functions, we have to take some extra steps. If you don’t need those, you can skip this part.
- First, copy the following files from (Processing Dir)/modes/java/libraries/opengl/library/:
gluegen-rt.jar jogl.jar opengl.jar
to (Clooj Project)/lib/.
- Now, to launch Clooj, you have to use a special command line:
java -Djava.library.path=(Processing Dir)/modes/java/libraries/opengl/library/macosx -jar /path/to/clooj-standalone.jar
- Note the /macosx on the end of that path—it points to the OS-specific dynamic libraries (.jnilib for OSX) instead of the jars. This should be changed for your operating system (i.e. windows32 or linux64).
- Now you can open one of the examples from the clj-processing repo and hit Command-E to run the whole file. This should open up an applet window with your Processing sketch running—and the best part is, you can modify the code at any time without restarting the applet!! Try changing a value in the draw function and hitting Command-Enter, which will only run that function (as opposed to the whole file). You can also run commands in the REPL and affect the applet—again, all while it’s still running. Super fun!