【问题标题】:How to pass command line options to the java compiler through the <javac> Ant task using <compilerarg value="">?如何使用 <compilerarg value=""> 通过 <javac> Ant 任务将命令行选项传递给 java 编译器?
【发布时间】:2021-02-04 01:36:52
【问题描述】:

要使用预览功能编译代码,javac 需要选项 --enable-preview--release

如果我使用line 属性将这些选项传递给&lt;javac&gt; Ant 任务(Ant 1.10.5),如下所示,编译成功。

<compilerarg line="--enable-preview --release 15"/>

但是如果我使用value 属性将它们作为单独的参数传递,如下所示,Ant 会抛出error: invalid flag: --release 15

<compilerarg value="--enable-preview"/>
<compilerarg value="--release 15"/>

由于 Ant 手册 says“强烈建议尽可能避免使用 line 版本”,我想知道如何使代码与 value 属性一起工作。有什么诀窍?

【问题讨论】:

    标签: ant javac


    【解决方案1】:

    需要三个参数,比如:

    <compilerarg value="--enable-preview"/>
    <compilerarg value="--release"/>
    <compilerarg value="15"/>
    

    ...否则,如您所见,“--release 15”被视为带有嵌入空格的单个参数。

    【讨论】:

    • 在我尝试过的所有组合中,我不得不错过那个......谢谢!
    猜你喜欢
    • 2011-05-07
    • 1970-01-01
    • 2013-07-03
    • 2010-11-30
    • 2013-02-01
    • 2015-10-13
    • 2016-11-05
    • 2012-12-23
    相关资源
    最近更新 更多