Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过ant macrodef传递变量命令行参数_Java_Ant - Fatal编程技术网

Java 通过ant macrodef传递变量命令行参数

Java 通过ant macrodef传递变量命令行参数,java,ant,Java,Ant,我有一个java程序MyClass,它接受一个必需的参数reqArg和一个可选参数myOptionalArg。我正试图为同样的目标编写ant <macrodef name="run-class"> <attribute name="reqArg" /> <sequential> <condition property="additionalArgs" value="${args}" else="">

我有一个java程序
MyClass
,它接受一个必需的参数
reqArg
和一个可选参数
myOptionalArg
。我正试图为同样的目标编写ant

  <macrodef name="run-class">
    <attribute name="reqArg" />
    <sequential>
      <condition property="additionalArgs" value="${args}" else="">
        <isset property="args" />
      </condition>
      <java classname="MyClass" failonerror="true" fork="true" classpath="${classpath}">
        <arg line="--reqArg @{reqArg}" />
        <arg line="${additionalArgs}" />
      </java>
    </sequential>
  </macrodef>

  <!--Separate target for each value of reqArg -->
  <target name="run-class-arg1">
    <run-class reqArg="arg1"/>
  </target>

有了上述功能,我可以像这样成功地调用程序,并且可以正常工作:

ant run-class-arg1-Dargs=“--myOptionalArg值”

是否有一种方法可以调整上述目标,以便调用方只需执行以下操作,而无需显式键入
-Dargs=“…”
。这将使调用者更容易记住语法

ant run-class-arg1—myOptionalArg值


谢谢

我不知道如何将任意参数直接传递给Ant

相反,考虑用shell脚本或批处理脚本包装Ant调用。

testbuild.xml 例如:

$ ./call-ant.sh hi there
...
 [echo] hi there
C:\>call-ant.bat hi there
...
 [echo] hi there
名为call-ant.bat的Windows批处理脚本 例如:

$ ./call-ant.sh hi there
...
 [echo] hi there
C:\>call-ant.bat hi there
...
 [echo] hi there
C:\>call-ant.bat hi there
...
 [echo] hi there