How can I test for JVM versions?

Erik Hatcher

If you're using Ant 1.4.1 or greater, the <condition> task works great. Here's an example that ought to give you what you need:

<project basedir="." default="test">

  <target name="get-jvm">
    <condition property="jvm.ok">
      <not>
        <or>
          <equals arg1="${ant.java.version}" arg2="1.1"/>
        </or>
      </not>
    </condition>
  </target>

  <target name="check-jvm" depends="get-jvm" unless="jvm.ok">
    <fail message="Wrong JVM - ${ant.java.version}"/>
  </target>
  <target name="test" depends="check-jvm">
    <echo message="JVM OK - ${ant.java.version}"/>
  </target>
</project>
There is no "greater than" or "less than" logic, but there is certainly room to add that if you'd like to tackle a patch to Ant's code. With combinations of <equal>, <and>, <or>, and <not> you should be able to achieve the precise control you need. Be sure to leave it open ended for JVM 1.4 and up (so you don't have to touch your build file when upgrading JVM's) - thats why I constructed my example with a <not> and <or>.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact