2006-12-19

Retroweaver: develop with 1.5, deploy with 1.4

After 2 months of development with Java 5 and targeting Weblogic 9.2, it turned out that the customer wants to run our application on Weblogic 8.1 due to licensing issues.

Before geting too desperate, I've found something really impressive: Retroweawer.

This tool lets you develop with Java 5 and then create Java 1.4 compatible class files. It is an Ant task which translates Java 5 bytecode to 1.4.

Feel free to use the language features of Java 5 (generics, extended for loops, static imports, autoboxing/unboxing, varargs, enumerations, annotations), Retroweaver will support them all.

But pay attention! It's highly reccomended to enable reference verification. Otherwise, you may experience ugly runtime errors like we did: we had to tweak Echo2 to fully support file download with IE and I compiled it using Java 5. Without reference verification I could create a corrupt release for WL8.1. Everything went well until I opened the GUI: Echo2 did reset the session immediately and there was no error message, nowhere! It took me about 1 day to find what went wrong here: class file incompatibility.

As I said this all can be avoid using reference validation. To set up it correctly, you will need the runtime classpath specified in the classpath property in the Retroweaver task. In other words, you will have to list the JVM 1.4 runtime jars plus all of your allplication jars. The 'pathconvert' Ant task will be your best friend here. Seethe relevent parts of our build.xml below:


<taskdef name="retroweaver"
classname="net.sourceforge.retroweaver.ant.RetroWeaverTask">
<classpath>
<fileset dir="util/retroweaver-2.0Beta2"
includes="**/*.jar"/>
</classpath>
</taskdef>

<fileset id="libs_build" dir="libs">
<include name="**/*.jar"/>
</fileset>

<fileset id="java14runtime"
dir="${JDK14_HOME}">
<include name="**/*.jar"/> <!-- This could be
a bit more sophisticated -->
</fileset>

<path id="weave.classpath">
<fileset refid="java14runtime"/>
<pathelement location="build/classes-14"/>
<fileset refid="libs_build"/>
</path>

<target name="weave" depends="build">
<mkdir dir="build/classes-14"/>
<pathconvert pathsep=";"
property="weave.classpath.str"
refid="weave.classpath"/>
<echo message="weave
classpath=${weave.classpath.str}"/>
<retroweaver destdir="build/classes-14"
target="1.4"
classpath="${weave.classpath.str}">
<fileset dir="build/classes">
<include name="**/*.class"/>
</fileset>
</retroweaver>
</target>


2 comments:

Safia said...

I am using J2me(it uses java 1.3)and I have a code in java 5 and I want to use it in my J2ME project. I used retroweaver, I followed first three steps and I am unable to understand the fourth one which says "Deploy your application, including the Retroweaver runtime library,
retroweaver-rt.jar."Kindly help me.

ambro23 said...

I guess retroweaver will not work neither on J2ME, nor Java 1.3.