ant buildfile setting javac location

喜欢而已 提交于 2019-12-23 09:01:43

问题


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


回答1:


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).




回答2:


This was pulled from the javac task documentation

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


来源:https://stackoverflow.com/questions/4865245/ant-buildfile-setting-javac-location

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!