You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Zarar Siddiqi <za...@utoronto.ca> on 2005/06/15 21:49:05 UTC
Detecting JDK Version using ANT
Hi,
Is there a clean way to detect what version of Java is being used when running a build file?
Some possible solutions include:
1) parsing the JAVA_HOME variable to detect the version number
2) Checking the existence of a file which is specific to a version
Both methods are somewhat brittle.
Is there a sureshot way of knowing whether ANT is being invoked using Java 1.5 or not?
Thanks in advance,
Zarar
Re: Detecting JDK Version using ANT
Posted by "Alexey N. Solofnenko" <A....@mdl.com>.
Java sets ${java.vm.version} property with its version.
- Alexey.
Zarar Siddiqi wrote:
> Hi,
>
> Is there a clean way to detect what version of Java is being used when
> running a build file?
>
> Some possible solutions include:
>
> 1) parsing the JAVA_HOME variable to detect the version number
> 2) Checking the existence of a file which is specific to a version
>
> Both methods are somewhat brittle.
>
> Is there a sureshot way of knowing whether ANT is being invoked using
> Java 1.5 or not?
>
> Thanks in advance,
> Zarar
>
>
--
------------------------------------------------------------------------
/ Alexey N. Solofnenko
home: http://trelony.cjb.net/
/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Detecting JDK Version using ANT
Posted by Peter Reilly <pe...@apache.org>.
Zarar Siddiqi wrote:
>Hi,
>
>Is there a clean way to detect what version of Java is being used when running a build file?
>
>Some possible solutions include:
>
>1) parsing the JAVA_HOME variable to detect the version number
>2) Checking the existence of a file which is specific to a version
>
>Both methods are somewhat brittle.
>
>Is there a sureshot way of knowing whether ANT is being invoked using Java 1.5 or not?
>
>
It is perhaps more important to check if ant is being invoked using java
1.5 or higher. The way the
build script used to build ant does this is to check the existance of a
specific class that has been
introduced in java 1.5.
The snippet from the build file for ant is:
<available property="jdk1.3+" classname="java.lang.StrictMath"/>
<available property="jdk1.4+" classname="java.lang.CharSequence"/>
<available property="jdk1.5+" classname="java.lang.Readable"/>
Peter
>Thanks in advance,
>Zarar
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Detecting JDK Version using ANT
Posted by "Alexey N. Solofnenko" <A....@mdl.com>.
Actually the best property is ${java.specification.version} it is just
two digit version 1.4 or 1.5.
- Alexey.
Ivan Ivanov wrote:
> Hello,
>
> you can try with java.version property:
>
> <project>
> <echo>$${java.version} is ${java.version}</echo>
> <echo>$${java.runtime.version} is
> ${java.runtime.version}</echo>
> <!-- Dumps all properties starting with "java" -->
> <echoproperties prefix="java"/>
> </project>
>
> Regards
> Ivan
>
> --- Zarar Siddiqi <za...@utoronto.ca> wrote:
>
>
>> Hi,
>>
>> Is there a clean way to detect what version of Java
>> is being used when running a build file?
>>
>> Some possible solutions include:
>>
>> 1) parsing the JAVA_HOME variable to detect the
>> version number
>> 2) Checking the existence of a file which is
>> specific to a version
>>
>> Both methods are somewhat brittle.
>>
>> Is there a sureshot way of knowing whether ANT is
>> being invoked using Java 1.5 or not?
>>
>> Thanks in advance,
>> Zarar
>>
--
------------------------------------------------------------------------
/ Alexey N. Solofnenko
home: http://trelony.cjb.net/
/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Detecting JDK Version using ANT
Posted by Zarar Siddiqi <za...@utoronto.ca>.
Thanks for clearing that up.
I'm sticking with ${java.specification.version} as suggested by Alexey.
Zarar
----- Original Message -----
From: "Stefan Bodewig" <bo...@apache.org>
To: <us...@ant.apache.org>
Sent: Thursday, June 16, 2005 3:00 AM
Subject: Re: Detecting JDK Version using ANT
> On Wed, 15 Jun 2005, Zarar Siddiqi <za...@utoronto.ca> wrote:
>
>> I'm assuming ${ant.java.version} is the version Ant is using in case
>> there are multiple JDK's installed
>
> No, it is the "flavor" of JDK Ant has detected at runtime, it doesn't
> trust the system properties and probes for certain features (existing
> classes, basically). Ant bases its decisions on which command line
> arguments javac or javadoc can deal with and many other things on the
> value of this property.
>
>> on the system and ${java.version} queries the JAVA_HOME variable.
>
> No. This is a system property set by the Java VM itself.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Detecting JDK Version using ANT
Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 15 Jun 2005, Zarar Siddiqi <za...@utoronto.ca> wrote:
> I'm assuming ${ant.java.version} is the version Ant is using in case
> there are multiple JDK's installed
No, it is the "flavor" of JDK Ant has detected at runtime, it doesn't
trust the system properties and probes for certain features (existing
classes, basically). Ant bases its decisions on which command line
arguments javac or javadoc can deal with and many other things on the
value of this property.
> on the system and ${java.version} queries the JAVA_HOME variable.
No. This is a system property set by the Java VM itself.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Detecting JDK Version using ANT
Posted by Zarar Siddiqi <za...@utoronto.ca>.
Thank you all.
${ant.java.version} and ${java.version} yield two different values. 1.5 and
1.5.0_01, respectively.
I'm assuming ${ant.java.version} is the version Ant is using in case there
are multiple JDK's installed on the system and ${java.version} queries the
JAVA_HOME variable.
Am I correct?
Thanks again.
----- Original Message -----
From: "Ivan Ivanov" <ra...@yahoo.com>
To: "Ant Users List" <us...@ant.apache.org>
Sent: Wednesday, June 15, 2005 4:06 PM
Subject: Re: Detecting JDK Version using ANT
> Hello,
>
> you can try with java.version property:
>
> <project>
> <echo>$${java.version} is ${java.version}</echo>
> <echo>$${java.runtime.version} is
> ${java.runtime.version}</echo>
> <!-- Dumps all properties starting with "java" -->
> <echoproperties prefix="java"/>
> </project>
>
> Regards
> Ivan
>
> --- Zarar Siddiqi <za...@utoronto.ca> wrote:
>
>> Hi,
>>
>> Is there a clean way to detect what version of Java
>> is being used when running a build file?
>>
>> Some possible solutions include:
>>
>> 1) parsing the JAVA_HOME variable to detect the
>> version number
>> 2) Checking the existence of a file which is
>> specific to a version
>>
>> Both methods are somewhat brittle.
>>
>> Is there a sureshot way of knowing whether ANT is
>> being invoked using Java 1.5 or not?
>>
>> Thanks in advance,
>> Zarar
>
>
>
>
> __________________________________
> Discover Yahoo!
> Get on-the-go sports scores, stock quotes, news and more. Check it out!
> http://discover.yahoo.com/mobile.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Detecting JDK Version using ANT
Posted by Ivan Ivanov <ra...@yahoo.com>.
Hello,
you can try with java.version property:
<project>
<echo>$${java.version} is ${java.version}</echo>
<echo>$${java.runtime.version} is
${java.runtime.version}</echo>
<!-- Dumps all properties starting with "java" -->
<echoproperties prefix="java"/>
</project>
Regards
Ivan
--- Zarar Siddiqi <za...@utoronto.ca> wrote:
> Hi,
>
> Is there a clean way to detect what version of Java
> is being used when running a build file?
>
> Some possible solutions include:
>
> 1) parsing the JAVA_HOME variable to detect the
> version number
> 2) Checking the existence of a file which is
> specific to a version
>
> Both methods are somewhat brittle.
>
> Is there a sureshot way of knowing whether ANT is
> being invoked using Java 1.5 or not?
>
> Thanks in advance,
> Zarar
__________________________________
Discover Yahoo!
Get on-the-go sports scores, stock quotes, news and more. Check it out!
http://discover.yahoo.com/mobile.html
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Question: List
Posted by Frank Hansen <fh...@swissonline.ch>.
Dear All,
Can some someone tell me the best way to get started on ANT under Windows I
have websphere Studio - is that possible to compile some script to get
familiar with the environment, or do I have to go LINUX. Not that Im not
familiar but just dont feel like going from machine to machine, but have it
all running on my labtop.
Any help is appreciated.
- Frank
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org