Java 通过ant macrodef传递变量命令行参数
我有一个java程序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="">
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