jGuru
Register Email     Password Forgot your
password?
HOME FAQS FORUMS DOWNLOADS ARTICLES PEERSCOPE LEARN

  Search   jGuru Search Help

Question How can I test for JVM versions?
Derived from A question posed by Dmitry Zakharov
Topics Tools:Build:Ant
Author Erik Hatcher PREMIUM
Created Nov 22, 2001


Answer
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>.


Is this item helpful?  yes  no     Previous votes   Yes: 1  No: 1



Comments and alternative answers

Comment on this FAQ entry

There are currently no comments

Ask A Question



 
Related Links

Ant FAQ

Ant Forum

Ant Homepage

Sun: Best Practices

Hatcher Ant Book

Hatcher Ant Book

Automate your build process using Java and Ant

Wish List
Features
About jGuru
Contact Us

 


Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers