开发者

Ant javac task running executable instead of java classes

I'm almost certain I can't 开发者_StackOverflow中文版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.


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"
  />


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜