wood burning stoves 2.0*
The moose likes Java in General and the fly likes Problem with ANT using a different JDK version Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem with ANT using a different JDK version" Watch "Problem with ANT using a different JDK version" New topic
Author

Problem with ANT using a different JDK version

Amir Pourteymour
Ranch Hand

Joined: Mar 06, 2008
Posts: 45
Hi,

Does anybody know if ANT by default uses a different version of JDK than the one JAVA_HOME is pointing to?

Cause when I print out my jdk versions, I get a older version comparing to when I run the class separately outside of ant.


Thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If you have JAVA_HOME defined it should use that. If you don't it will try to work out where JAVA_HOME is (assuming you are using the batch or shell scripts to run it).

Some Ant tasks can specify a different JVM depending on what they do. Check the docs.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Amir Pourteymour
Ranch Hand

Joined: Mar 06, 2008
Posts: 45
Do you think if I add a JAVA_HOME property in my ant, it starts using this instead of whatever it has?



thanks,
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

I'm not sure, but I doubt it. AFAIK the JAVA_HOME variable is used when starting Ant, which is a Java program. I don't see it changing its own JVM just like that.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Amir Pourteymour
Ranch Hand

Joined: Mar 06, 2008
Posts: 45
if I compile my class like this =>
javac -source 1.3 -target 1.4 JVMVersion.java

it works very well and gives me JDK versions it is using:
Java Version : 1.6.0_03
Java vendor : Sun Microsystems Inc.
Java home : C:\Program Files\Java\jre1.6.0_03
*************
JVM specification version : 1.0
JVM Version : 1.6.0_03-b05
*************
JRE specification version : 1.6
--------------------------------------
If I again compile them like javac -source 1.3 -target 1.4 JVMVersion.java
and call them from an ant file to run. It returns different JDK version:
[java] Java Version : 1.4.2_05
[java] Java vendor : Sun Microsystems Inc.
[java] Java home : C:\Borland\BDP\jdk\jdk1.4.2\jre
[java] *************
[java] JVM specification version : 1.0
[java] JVM Version : 1.4.2_05-b04
[java] *************
[java] JRE specification version : 1.4
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

What's the output of "echo %JAVA_HOME%" (or $JAVA_HOME for non-Windows OSes)?

The JAVA_HOME can point to a completely different JDK than the java(.exe) that is on the system path.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


C:\Borland\BDP\jdk\jdk1.4.2\jre

You are not running Ant from JBuilder, are you?
Amir Pourteymour
Ranch Hand

Joined: Mar 06, 2008
Posts: 45
No I am not. Actually I have a separate folder for my ant, which my ANT_HOME is pointing to.
Amir Pourteymour
Ranch Hand

Joined: Mar 06, 2008
Posts: 45
Originally posted by Rob Prime:
What's the output of "echo %JAVA_HOME%" (or $JAVA_HOME for non-Windows OSes)?

The JAVA_HOME can point to a completely different JDK than the java(.exe) that is on the system path.



This is the output for that => C:\JAVA
 
 
subject: Problem with ANT using a different JDK version
 
Similar Threads
Unsupported major.minor version 50.0
Ant 1.5.4 and JDK 1.3.1
Giving error when compiling with ant but not showing the error in eclips
How to set different JDKs for different projects in Eclipse 3.0.1?
Problem with running my class inside ANT