Kevin
Kevin

Reputation: 175

Ant javac task running executable instead of java classes

I'm almost certain I can't really do this without writing my own Task classes, but I thought I'd ask anyway. Is there some magic property or ant task that works just like <javac>, but runs my $JAVA_HOME/bin/javac executable file instead of running the code from the javac classes in $JAVA_HOME/lib/tools.jar? The reason I'd like to do this is because I can change the javac binary to always compile with Xlint, it'd be nice to have all the build.xml files around do that too without editing them. (And some have implicit javac calls through other tasks...) The compiler attribute of <javac> is meant for the class code, it doesn't let you simply specify a file to run.

Upvotes: 0

Views: 1249

Answers (2)

Jayan
Jayan

Reputation: 18468

Ant can redefine existing to have new behavior using preset. The preset definition generates a new definition based on a current definition with some attributes or elements preset. This with compilerarg flag could help you.

Upvotes: 0

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74800

The Javac task has the fork attribute, and also the executable one. Combine these.

Also, you might want to set compiler=extJavac, though I'm not sure if this changes something.

Here is a quote from the examples section:

If you want to run the javac compiler of a different JDK, you should tell Ant, where to find the compiler and which version of JDK you will be using so it can choose the correct command line switches. The following example executes a JDK 1.1 javac in a new process and uses the correct command line switches even when Ant is running in a Java VM of a different version:

  <javac srcdir="${src}"
         destdir="${build}"
         fork="yes"
         executable="/opt/java/jdk1.1/bin/javac"
         compiler="javac1.1"
  />

Upvotes: 1

Related Questions