ERXCompilerProxy

(c) 2001,2002, Anjo Krank (ak@prnet.de), all rights reserved

About

Ever got tired of the long time WO 5 takes to rebuild your project after every tiny change you make? Ever got really tired because you had to build/install those frameworks every ten minutes? Not afraid of living on the edge? Then this hack is for you!

ERXCompilerProxy is a class that creates a rapid-turnaround mode for WebObjects 5 for Java similar to how you use WebScript with WO 4.5.1. Instead of recompiling your Application or Frameworks, you simply change the source code in question and reload your page. In some cases, you may also have to restart your Application but you won't have to rebuild it.

ERXCompilerProxy is especially well suited for DirectToWeb applications. The restrictions of Java's classloading are partially compensated by the highly dynamic nature of D2W apps.

Installation

Check if you have jikes installed in /usr/bin.

Usage

To use this framework you must complete a few easy steps and you will very seldom have to rebuild or even restart your project again:

That's all. Now build your app, make a change in Main.java and reload. You should see the changed version and a message from ERXCompilerProxy in the console.

What it does

The ERXCompilerProxy does several things to works it's magic. First, on startup, it registers for the ApplicationDidFinishLaunching Notification. When the App starts, it reads the CPFileList.txt files from your currently opened projects to find out about the files to watch. So remember to have your framework projects open in PB.

It also registers for the ApplicationWillDispatchRequest Notification, which gets triggered whenever a page is requested. It tries to compile the files that have changed and throws an Exception describing the errors if there where any and then aborts further handling of the request - you will get an error from your browser. However, if everything went well, it creates a new ClassLoader and throws away the component definition cache and a few other things. Then, when the next "pageWithName" is called, the updated class will be used.

This is slightly different from how WebScript handled things. In Java, you simply can't change an Object's class implementation at runtime - so if you already have a page (or any other Object) this object will not use the newer class. Only Objects created after the compilation will have new behaviour.

The freshly compiled files will be put into your App's Resources/Java directory into the proper package hierarchy. So, if you simply restart your App, the newer files will be used. When you re-build your project, your normal .jar will contains the correct classes anyway.

NOTE: Since all new class files end up in Resources/Java, when you clean-build your App, you also need to recompile your frameworks when you have changed classes there! A normal build will not delete the files, so recompilation of the frameworks is not needed.

Knows bugs and limitations

Of course, this code is highly experimental. It may toast your goldfish for all I know, so you are on your own if you run into trouble.

Version History

24/07/07 - 1.4 included in ERExtensions, renamed to ERXCompilerProxy.

12/06/01 - 1.3 fixed several bugs, added framework turnaround support.

07/26/01 - 1.2 fixed several bugs, vastly simplified installation. Removed the need to clean your project.

07/08/01 - 1.0 initial release