ktm5124
ktm5124

Reputation: 12123

ant buildfile setting javac location

I'm editing the buildfile of an old project. When I add some jar files to the project that use Java 1.6, it won't build. It says

[javac] javac: invalid target release: 1.6

So clearly I need to tell the ant buildfile to use javac 1.6.

How do I do this? I have JDK1.6 installed on my system, but the default javac is 1.5. I don't want to change the default javac... I just want to set the javac location in this one proejct to JDK1.6/bin/javac. How do I do this in the XML of an ant buildfile?

Thanks,
ktm

Upvotes: 7

Views: 7003

Answers (2)

dogbane
dogbane

Reputation: 274878

You can create a wrapper script in which you change your JAVA_HOME before executing ant.

e.g. build.sh

export JAVA_HOME=/path/to/jdk1.6
ant "$@"

Now when you call build.sh it will use java6 for both javac, java and any other commands.

IMO this is better than fiddling with the build.xml (and forking a new javac process).

Upvotes: 3

Aaron McIver
Aaron McIver

Reputation: 24723

This was pulled from the javac task documentation

<javac srcdir="" 
         destdir=""
         executable="path-to-java16-home/bin/javac" 
         fork="true"
         taskname="javac1.6" />

Upvotes: 7

Related Questions