You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Xavier Loiseau <xl...@yahoo.fr> on 2002/11/08 14:41:19 UTC

Checking the java version

Hi,


What is the simplest way of checking the java version
before running an application ?

What is the simplest way of checking the java version
before compiling an application ?

This is an important issue since several java versions
are often installed in a same computer.

I have tried to solve both problems through the ant
file that you will find below.

But I am still wondering if it is the right way of
solving those problems.

Could anybody confirm that to me ?

Kind regards.


Xav




<project name="sample" default="build" basedir="../">

  <target name="run" depends="checkjavaversion">
    <java classname="MyClass"
          fork="yes"
          classpath="MyClassPath" />
  </target>    

  <target name="compile" depends="checkjavaversion">
    <javac classpath="MyClassPath"
           srcdir="MySourceDir"
           destdir="MyDestDir"
           includes="**/*.java" />
  </target>
            
  <target name="checkjavaversion" >

    <condition property="isJavaVersionCorrect">
        <equals arg1="${ant.java.version}"
                arg2="1.3" />
    </condition>

    <fail unless="isJavaVersionCorrect" 
          message="The java version should be 1.3 !"
/>

  </target>

</project>



___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Checking the java version

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 8 Nov 2002, Ilja Preu <pr...@disy.net> wrote:

> I am using ${java.specification.version} instead of
> ${ant.java.version} - I don't know wether this makes a difference,
> though.

Yes, it does.

${java.specification.version} is a system property JVM implementors
can (must?) implement, but I'm not sure whether the rules are well
defined here.  I wouldn't bet that Kaffee will set it correctly for
example.

${ant.java.version} is what Ant has detected.  Ant's detection code
tries to load a certain set of classes that have been added in certain
Java versions, the code is

        try {
            javaVersion = JAVA_1_0;
            javaVersionNumber=10;
            Class.forName("java.lang.Void");
            javaVersion = JAVA_1_1;
            javaVersionNumber++;
            Class.forName("java.lang.ThreadLocal");
            javaVersion = JAVA_1_2;
            javaVersionNumber++;
            Class.forName("java.lang.StrictMath");
            javaVersion = JAVA_1_3;
            javaVersionNumber++;
            Class.forName("java.lang.CharSequence");
            javaVersion = JAVA_1_4;
            javaVersionNumber++;
        } catch (ClassNotFoundException ...

In a certain sense, this is more reliable than
${java.specification.version} as Ant detects what is there instead of
what the VM claims to be.

On the other hand, it will say that Kaffee is Version 1.2, even though
it doesn't ship Swing.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Checking the java version

Posted by Ilja Preuß <pr...@disy.net>.
Looks OK to me.

I am using ${java.specification.version} instead of ${ant.java.version} - I
don't know wether this makes a difference, though.

Regards, Ilja



----- Original Message -----
From: "Xavier Loiseau" <xl...@yahoo.fr>
To: <an...@jakarta.apache.org>
Sent: Friday, November 08, 2002 2:41 PM
Subject: Checking the java version


> Hi,
>
>
> What is the simplest way of checking the java version
> before running an application ?
>
> What is the simplest way of checking the java version
> before compiling an application ?
>
> This is an important issue since several java versions
> are often installed in a same computer.
>
> I have tried to solve both problems through the ant
> file that you will find below.
>
> But I am still wondering if it is the right way of
> solving those problems.
>
> Could anybody confirm that to me ?
>
> Kind regards.
>
>
> Xav
>
>
>
>
> <project name="sample" default="build" basedir="../">
>
>   <target name="run" depends="checkjavaversion">
>     <java classname="MyClass"
>           fork="yes"
>           classpath="MyClassPath" />
>   </target>
>
>   <target name="compile" depends="checkjavaversion">
>     <javac classpath="MyClassPath"
>            srcdir="MySourceDir"
>            destdir="MyDestDir"
>            includes="**/*.java" />
>   </target>
>
>   <target name="checkjavaversion" >
>
>     <condition property="isJavaVersionCorrect">
>         <equals arg1="${ant.java.version}"
>                 arg2="1.3" />
>     </condition>
>
>     <fail unless="isJavaVersionCorrect"
>           message="The java version should be 1.3 !"
> />
>
>   </target>
>
> </project>
>
>
>
> ___________________________________________________________
> Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
> Yahoo! Mail : http://fr.mail.yahoo.com
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>