wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes Specify Java Version in build.xml 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 » Engineering » Ant, Maven and Other Build Tools
Bookmark "Specify Java Version in build.xml " Watch "Specify Java Version in build.xml " New topic

Specify Java Version in build.xml

Harish Tam
Ranch Hand

Joined: Feb 17, 2005
Posts: 71


I want to build a jar file with 1.4 version of java, i have both 1.4 and 1.5 installed on my machine and 1.5 is the default java jre and everytime it complies it uses java 1.5 is there a way we can specify the java version of compiler in the build.xml in ant process. or is there any other way so that ant uses 1.4 for compilation.

I think we can do this using the build.properties file for ANT but have no clue of this can anybody help me in this.


SCJP 1.4, SCWCD 1.4
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3274

You can set your JAVA_HOME in the ant script (or as you say through build.properties file) in order to pick up the JDK you want for that build

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Peter Johnson

Joined: May 14, 2008
Posts: 5812

For the <javac> task, set the source and target properties. Example:

JBoss In Action
Harish Tam
Ranch Hand

Joined: Feb 17, 2005
Posts: 71

I got it after some time.

This is what you need to specify while doing javac in ANT build file

<javac srcdir="${src.dir}" destdir="${dist.dir.classes}" executable="D:\j2sdk1.4.2_05\bin\javac" compiler="javac1.4"/>

I agree. Here's the link: http://aspose.com/file-tools
subject: Specify Java Version in build.xml
Similar Threads
How to specify a JRE range in jnlp file?
Need some Guidance in using Java 1.6 with ANT
Buildfile: build.xml does not exist! Build failed
Specify classpath for runtime
Java version in build file