可选ANT ARG [英] Optional ANT arg

查看:199
本文介绍了可选ANT ARG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一只蚂蚁ARG值可选包括无需进行2个目标,这将是除了额外的ARG基本相同。例如:

 <目标名称=A取决于=C> ...< /目标与GT;<目标名称=B取决于=C> ...< /目标与GT;<目标名称=C>
    < java的叉=真正的...>
        < jvmarg ... />
        <参数... />
        <参数... />
        ...
        #现在,如果依赖是A,没有更多的ARGS
        #如果选自B
            < ARG值=XXX/>
    < / JAVA>
< /目标与GT;


解决方案

而不是取决于 ING的任务C,你可以使用的 Antcall 任务传递 B 参数为参数

 <目标名称=A>
  < antcall目标=C/>
  ....
< /目标与GT;<目标名称=B>
  < antcall目标=C>
    < PARAM NAME =extra_argVALUE =XXX/>
  < / antcall>
  ...
< /目标与GT;<目标名称=C>
    < java的叉=真正的...>
        < jvmarg ... />
        <参数... />
        <参数... />
        < ARG值=$ {} extra_arg/>
    < / JAVA>
< /目标与GT;

编辑:尼科在评论中指出,如果该值是从A答案可以扩展到使用条件任务未设置不起作用该参数设置为空字符串。

 <条件属性=argToUseIfFromB否则=>
  <使用isset财产=extra_arg/>
< /条件>
< java的叉=真正的...>
    < jvmarg ... />
    <参数... />
    <参数... />
    < ARG值=$ {} argToUseIfFromB/>
< / JAVA>

进一步编辑:
由于我们无法得到的参数被视为可选的,我们可以从每个父任务,整个传递命令行。目标 A 只能通过共同的论点; B 将通过一个额外的参数。在参数的Ant手册解释它比我好。

 <目标名称=A>
  < antcall目标=C>
    < PARAM NAME =JAVA_ARGSVALUE =arg_a arg_b/>
  < / antcall>
  ....
< /目标与GT;<目标名称=B>
  < antcall目标=C>
    < PARAM NAME =JAVA_ARGSVALUE =arg_a arg_b extra_arg/>
  < / antcall>
  ...
< /目标与GT;<目标名称=C>
    < java的叉=真正的...>
        < jvmarg ... />
        < ARG行=$ {} JAVA_ARGS/>
    < / JAVA>
< /目标与GT;

I would like to have an ant arg value optionally included without having to make 2 targets which would be basically the same except for the extra arg. For example:

<target name="A" depends="C">...</target>

<target name="B" depends="C">...</target>

<target name="C">
    <java fork="true" ...>
        <jvmarg .../>
        <arg .../>
        <arg .../>
        ...
        # now, if the dependency is from A, no more args
        # if from B
            <arg value="xxx"/>
    </java>
</target>

解决方案

Rather than depending on task C, you could use the Antcall task to pass the B argument as a param.

<target name="A" >
  <antcall target="C" />
  ....
</target>

<target name="B" >
  <antcall target="C" >
    <param name="extra_arg" value="xxx" />
  </antcall>
  ...
</target>

<target name="C">
    <java fork="true" ...>
        <jvmarg .../>
        <arg .../>
        <arg .../>
        <arg value="${extra_arg}"/>
    </java>
</target>

EDIT: As Nico points out in the comment, this doesn't work if the value is unset from A. The answer can be extended to use the condition task to set the argument to a null string.

<condition property="argToUseIfFromB" else="">
  <isset property="extra_arg" />      
</condition>
<java fork="true" ...>
    <jvmarg .../>
    <arg .../>
    <arg .../>
    <arg value="${argToUseIfFromB}"/>
</java>

FURTHER EDIT: Since we can't get the arguments to be recognised as optional, we can pass in the whole command line from each parent task. Target A would only pass the common arguments; B would pass through an extra argument. The Ant manual on arguments explains it better than me.

<target name="A" >
  <antcall target="C">
    <param name="java_args" value="arg_a arg_b" /> 
  </antcall>
  ....
</target>

<target name="B" >
  <antcall target="C" >
    <param name="java_args" value="arg_a arg_b extra_arg" />
  </antcall>
  ...
</target>

<target name="C">
    <java fork="true" ...>
        <jvmarg .../>
        <arg line="${java_args}"/>
    </java>
</target>

这篇关于可选ANT ARG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆