Skip to content

How to Build clj-processing

2012 March 1
by Tedb0t

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.

  1. 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.
  2. Build the clj-processing core.  This is the most complicated part; instructions are for OSX—other OSes have similar commands.
  3. Clone the repo from github.
  4. 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
  5. From a terminal (on OSX, assuming you have Processing in your Applications folder):
    export CLASSPATH="/Applications/Processing.app/Contents/Resources/Java:/Applications/Processing.app/Contents/Resources/Java/modes/java/libraries/opengl/library"
  6. From the same terminal, in the clj-processing directory, run
    ant

    If you don’t have ant, you need to install Java.

  7. This should build the processing.core.jar.  Now open Clooj and make a new project and note where you save it.
  8. Make a lib/ folder in the root of your Clooj project folder.
  9. Copy processing.core.jar and Processing’s core.jar file to your Clooj project lib/ folder.
  10. 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
  11. To get OpenGL functions, we have to take some extra steps. If you don’t need those, you can skip this part.
    1. First, copy the following files from (Processing Dir)/modes/java/libraries/opengl/library/:
      gluegen-rt.jar
      jogl.jar
      opengl.jar

      to (Clooj Project)/lib/.

    2. 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
    3. 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).
  12. 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!

Related Posts:


No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS