Search this blog

Loading...

Friday, May 6, 2011

Edit and continue is fun...

Update: I've noticed that Intellij IDEA (which has a free Community Edition) also supports hotreloading of java classes. Didn't try it though.

Even if I use Processing for small prototypes and stuff like that, I've always restricted myself to its own sketch IDE, even if it's fairly bad I never made big processing projects, I like its minimal interface and I'm not really the kind of guy that cares too much about his editor.

Also, the popular alternative is Eclipse an IDE that is the de-facto standard in the Java world and its known to be huge, slow and generally a mess. The few times I had to use Java I went with the simple and beautiful DrJava "educational" IDE instead.

Oh just how wrong I was about that. It turns out that Processing in Eclipse is just amazing, as Eclipse supports edit-and-continue ("hotswapping" if we don't want to stick to the MS lingo, it's a fairly old feature of the JVM)
Now you won't get anywhere near the awesomeness of something like Fields, that was designed from the grounds up as an interactive coding tool, but well, it's 100 times better than the Sketch IDE and it's really enjoyable.

So assuming that you know nothing about Eclipse, just like me, here is a step by step guide to coding fun:

Step.1
Download the most tiny, stripped down version of Eclipse possible. This can be quite a challenge as Eclipse comes in many bloated flavours by default. 

The tiniest of the prepackaged ones seems to be Eclipse Classic, that just includes all the Eclipse sources plus the CVS versioning plus the plugin development environement... 

Luckily, there is a customization service run by Yoxos here: http://ondemand.yoxos.com/geteclipse/start or https://yoxos.eclipsesource.com/discover.html, just select from the Components tab the "Eclipse Java Development Tools" and that should do the trick. It's "only" 85mb!

Note: If you're not lazy like me you can read this and learn the Eclipse shortcuts. Otherwise, include in the custom download also the C++ development platform. Now the package should be around 120mb, but you'll get the Visual Studio keybindings (preferences/general/keys)

Step.2
Download Processing and locate the core.jar library. There might be other jar files alongside it, most probably, you'll need them all (in the current processing v2.1 you'll need core, jogl-all and jogl-natives-, gluegen-rt and gluegen-rt-natives-) In my case, being on OSX Processing comes packages in a nice .app structure, I used muCommander to extract the files I needed.

Step.3
Run Eclipse and create a new Java project. Select the package you just created, right-click and select "Build Path/Configure Build Path/Libraries/Add External Jar" and select the Processing jar libraries. Then add a new class, named as the project and type something like this:

import processing.core.PApplet;
public class Test extends PApplet {

    public void setup()
    {
        size(512,512,P3D);
    }
    public void draw()
    {
        background(0);
        sphere(100);
    }
}

Step.4
Launch the debugger. Notice that every time you save the class, the processing window automatically refreshes. Have fun!

P.S. Processing has many extension libraries and tools. Among these there are a few live-coding projects, like this one. I didn't try these yet.

Note: IntelliJ Idea also has edit-and-continue for Java and has a free "community edition"

1 comment:

Anonymous said...
This comment has been removed by a blog administrator.