Glassfish 2.x and OpenJDK

Here is a small article about Glassfish and OpenJDK as I’ve had an error and have not found the solution anywhere else.

When installing Glassfish 2.2 on Linux, I had this error message:

/opt/glassfish/setup-cluster.xml:160: Glassfish requires JDK 1.5 or higher, you have java version "1.7.0_03-icedtea"

This happens when I try to build the setup-cluster.xml file with ant:

sudo ant -f setup-cluster.xml

After too many hours of research, I’ve seen that the Java version was checked in a wrong way in the XML file. It needs Java >= 1.5 and I have Java 1.7, but the script only checks if the Java version is 1.6 or 1.5, so I’ve added the third line, so the test passes if the version is 1.7:

<condition property="java.version.acceptable"> 
    <contains string="${}" substring="1.5"/>
    <contains string="${}" substring="1.6"/>
    <contains string="${}" substring="1.7"/>

I’ve tried this after reading and according to the author, glassfish-installer-v2-b58g doesn’t work with OpenJDK even with this trick, but it works fine with glassfish 2.1.1_b31g-1 (the current version in ArchLinux’s AUR repository).

PS: for those who have Arch, the ant command is located in /usr/share/java/apache-ant/bin/ which is not usually in the PATH.