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,是否可以执行以下操作 <target name="path-test"> <property name="d.file" value="ant/d.fileset" /> <property name="c.file" value="ant/c.fileset" /> <property name="e.file" value="ant/e.fileset" /> <available property="c.fil

是否可以执行以下操作

<target name="path-test">
   <property name="d.file" value="ant/d.fileset" />
   <property name="c.file" value="ant/c.fileset" />
   <property name="e.file" value="ant/e.fileset" />

   <available property="c.file.exists" file="${c.file}" />
   <available property="d.file.exists" file="${d.file}" />
   <available property="e.file.exists" file="${e.file}" />

   <path id="classPathRef">
     <fileset dir="${depot.dir}">
       <include name="${c.file}" if="c.file.exists" />
       <include name="${d.file}" if="d.file.exists" />
       <include name="${e.file}" if="e.file.exists" />
     </fileset>
   </path>
 </target> 

在这个场景中,每个文件集文件将包含一个JAR列表,我希望这些JAR最终出现在classPathRef中。

Doh

<target name="path-test">
   <property name="d.file" value="ant/d.fileset" />
   <property name="c.file" value="ant/c.fileset" />
   <property name="e.file" value="ant/e.fileset" />

   <available property="c.file.exists" file="${c.file}" />
   <available property="d.file.exists" file="${d.file}" />
   <available property="e.file.exists" file="${e.file}" />

   <path id="classPathRef">
     <fileset dir="${depot.dir}">
       <includesfile name="${c.file}" if="c.file.exists" />
       <includesfile name="${d.file}" if="d.file.exists" />
       <includesfile name="${e.file}" if="e.file.exists" />
     </fileset>
   </path>
 </target> 

我建议您使用常春藤来管理您的类路径

在构建文件中,使用retrieve命令将JAR复制到专用目录中:

<ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]"/>

注意conf参数。这是指常春藤配置(类似于Maven中的范围)。它允许您对所依赖的每个罐子进行分类

既然每个JAR集合都方便地位于不同的目录中,那么构建文件中的路径声明就变得很简单了:

<path id="compile.path">
    <fileset dir="${lib.dir}/compile"/>
</path>

<path id="test.path">
    <fileset dir="${lib.dir}/test"/>
</path>

<path id="runtime.path">
    <fileset dir="${lib.dir}/runtime"/>
</path>

定义jar分组的复杂性委托给了ivy及其配置管理:

下面是一个控制ivy.xml文件的示例


魔法位是与每个依赖项关联的conf属性。例如,Junit被声明为测试的一部分,这意味着它只出现在测试路径中。由于声明配置的方式,其他路径将出现在所有3个路径中

<ivy-module version="2.0">
    <info organisation="apache" module="hello-ivy"/>
    <configurations>
        <conf name="compile" description="Libraries needed for compilation"/>
        <conf name="runtime" extends="compile" description="Libraries that should be included when deploying the code" />
        <conf name="test" extends="runtime" description="Additional test libraries, not deployed" />
    </configurations>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.0" conf="build->default"/>
        <dependency org="commons-cli" name="commons-cli" rev="1.0" conf="build->default"/>
        <dependency org="junit" name="junit" rev="4.7" conf="test->default"/>
    </dependencies>
</ivy-module>