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
参数化Ant脚本以构建同一文件的两个版本_Ant - Fatal编程技术网

参数化Ant脚本以构建同一文件的两个版本

参数化Ant脚本以构建同一文件的两个版本,ant,Ant,我们有一个Java小程序项目,我们使用Ant生成包装HTML,它看起来有点像这样: <target name="build-applet" description="Build web applet" depends="set-build-properties, set-properties"> <antcall target="clean" /> <antcall target="clean-applet" /> <antc

我们有一个Java小程序项目,我们使用Ant生成包装HTML,它看起来有点像这样:

<target name="build-applet" description="Build web applet" depends="set-build-properties, set-properties">  
    <antcall target="clean" />
    <antcall target="clean-applet" />
    <antcall target="set-version" />
    <antcall target="compile" />
    <antcall target="jar" />
    <antcall target="applet" />
</target>

<target name="applet">      
    <replace file="${applet.dir}/${applet.html.file}">          
        <replacefilter token="@jar.file@" value="${applet.jar.file}"/>
        <replacefilter token="@assets.file@" value="${applet.assets.file}"/>
        <replacefilter token="@codebase@" value="${applet.codebase}"/>
</target>

请注意,
${applet.codebase}
必须是加载applet的URL,例如mysite.com/game。它是在属性文件中设置的


现在,我希望能够将这个小程序构建到两个不同的位置,这是实时/测试设置的一部分。e、 g一个在mysite.com/game上访问,另一个在mysite.com/test上访问。除了
${applet.codebase}
之外,它几乎可以正常工作,因为这在每种情况下都需要不同。我原以为我可以有
${applet.codebase}
${applet.codebase\u test}
,但我不知道怎么做。也许有一种方法可以将一个标志从
buildapplet
传递到
applet
目标中,并添加两个顶级目标
buildapplet-live
buildapplet-test
,它们只需使用参数调用
buildapplet

为什么不简单地
ant-Dapplet.codebase=which build.xml
,意思是set${applet_codebase}作为用户属性(=通过-Dkey=value设置的属性)?

因为ant脚本和相关属性文件是我们Eclipse项目的一部分…除非我误解了你,否则你的解决方案意味着将命令行变量传递给ant?是的,也可以使用Eclipse Run As>ant Build…第二个入口另一个稍微相关的重构:将ant调用更改为clean、clean applet、set version、compile和jar创建小程序的依赖项列表中的条目。让ant为您管理依赖关系图会更干净。我也完全同意小程序应该放弃,而将参数传递给ant,或者至少应该是一个宏