I am trying to compile my java project with Java 9. I am using the java.xml.bind package so I need to use the -addmods option for compiling. Ant 1.9.7 does not seem to support this new feature. Does ant support -addmods option for Java 9 compiler?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There is no explicit support in any released version of Ant at this point in time. But you should be able to use <jvmarg>
for that
<java ....>
<jvmarg value="--add-modules"/>
<jvmarg value="module.name.to.add"/>
<jvmarg ..../>
</java>
If you are asking about <javac>
rather than <java>
, <compilerarg>
can be used instead.
There are quite a few ways that Java 9 manages to break Ant - and 1.9.8 and 1.10.x will contain a lot of fixes for it (there will be new releases soon once the last known issues have been ironed out). Right now there is no explicit support for --add-modules
, though, only for modulepath
and upgrademodulepath
which have been added in Ant 1.9.7.
IMHO - Would be a good enhancement request though.
回答2:
Use at least Ant 1.10.1 and do the following in build.xml:
<condition property="java9">
<equals arg1="${ant.java.version}" arg2="9"/>
</condition>
<java classname="....." fork="true">
<classpath>
<pathelement location="...."/>
</classpath>
<jvmarg value="--add-modules" if:set="java9" />
<jvmarg value="java.xml.bind" if:set="java9" />
...
</java>