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
By default, javac compiles each source file to a class file in the same directory as the source file. However, it is recommended to specify a separate destination directory with the -d option described in Standard Options.
Typically, Ant's build file, called build. xml should reside in the base directory of the project.
Ant Javac task is used to compile Java source file. It scans source and destination directory to compile the source file. It only compiles if either . class is not present or .
As Ant runs, it displays the name of each target executed. As our example output shows, Ant executes prepare followed by compile . This is because compile is the default target, which has a dependency on the prepare target.
This was pulled from the javac task documentation
<javac srcdir=""
destdir=""
executable="path-to-java16-home/bin/javac"
fork="true"
taskname="javac1.6" />
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With