Pebble 2.0.1 on Java 1.4

Home, Bangkok, Thailand, 2006-12-11

#sysadmin

This evening I found time to upgrade my site to Pebble 2.0.1. My host is still on Java 1.4, so I had to make the same patches as I made when getting Pebble 2.0.0 RC2 running on Java 1.4.

Thankfully the changes are very simple. I’ve attached the SVN diff which can be applied as a patch, but I’ll also go through the changes here.

First download Retroweaver 2 Beta 2 and unzip it somewhere on your workstation. Also SVN checkout the 2.0.1 tag of Pebble from SourceForge.

Build Script Changes

Now make the following changes to Pebble’s build.xml:

In the properties section at the top of the build script, add the following property tag at line 16:

  <property name="retroweaver.home"
    value="C:/path-to/retroweaver-2.0Beta2" />

You’ll need to set the value of this property to point to wherever you unzipped the Retroweaver distribution. Next, in the compile target, insert the following at line 53:

<!-- Retroweave the 1.5 classes to be 1.4 compatible -->
<taskdef name="retroweaver"
  classname="net.sourceforge.retroweaver.ant.
    RetroWeaverTask">
  <classpath>
    <fileset dir="${retroweaver.home}/lib" 
      includes="**/*.jar" />
    <fileset dir="${retroweaver.home}/release" 
      includes="**/*.jar" />
  </classpath>
</taskdef>

<retroweaver srcdir="${classes.dir}" />

Insert the following at line 118 to include the Retroweaver runtime in your WAR file.

<fileset dir="${retroweaver.home}/release">
  <include name="retroweaver-rt-2.0Beta2.jar" />
</fileset>

And finally, insert the following in the junit tag’s classpath at line 172:

  <pathelement 
    location="${retroweaver.home}/release/retroweaver-rt-2.0Beta2.jar"  />
  <pathelement 
    location="${retroweaver.home}/lib/backport-util-concurrent.jar" />

At this point, with your JAVA_HOME pointed at a 1.5 JDK, you should be able to run the dist target from the Ant build successfully. In the output from Ant, you’ll see something like this:

    [javac] Compiling 391 source files to E:\wrk\pebble-2.0.1\build\classes
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
[retroweaver] Processing 401 classe(s)
[retroweaver] 401 classe(s) weaved.

Also, all of the JUnit test cases should run successfully.

Java Code Changes

Retroweaver is pretty cool, but it can’t make static code compiled on Java 1.5 work in 1.4. So far I’ve only come across one place where this causes a breakage, which is in the email address validation that occurs during comment posting. To fix it, in net/sourceforge/pebble/web/action/AbstractCommentAction.java, replace this code on line 54:

  MailUtils.validate(comment.getEmail(), context);

with this:

if (comment.getEmail() != null &&
  !comment.getEmail().matches(
  "[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\\.[A-Za-z]{2,}")) {

  context.addError(comment.getEmail() +
    " is not a valid e-mail address");
}

Deployment

You always have to build the patched Pebble with JDK 1.5. The patched version will still run with 1.5 if you need it to. After you’ve built Pebble with 1.5, make sure Tomcat is seeing a 1.4 JDK.

There is a 1.4 compatibility patch available for Tomcat 5. Prepare your Tomcat container by unzipping the compatibility patch into it. You might like to test the patched Tomcat on it’s own before deploying your patched Pebble into it.

Finally, drop your patched Pebble war into your patched Tomcat. When it’s deployed, you should be able to use Pebble as normal. Note if you happen to run Tomcat with JDK 1.5, you’ll need to manually clear Tomcat’s work directory of generated files before you run it with 1.4, otherwise you’ll get a bunch of class format errors.

Patch File

My patch to run Pebble 2.0.1 on Java 1.4 is available here.