2009-10-12 56 views
1

如何将目录列表转换为.jar文件列表? 似乎使用Copy Task和Mappers是这样做的正确方法,但我没有找到任何嵌套元素从目录中创建一个jar文件。如何使用Ant将目录转换为.jar文件

当然,目录列表将被计算出来,而不是在蚂蚁脚本中进行硬编码。

例如,foo目录包含bar1,bar2和bar3目录。该脚本将从bar1目录创建bar1.jar,从bar2目录创建bar2.jar并从bar3目录创建bar3.jar目录 脚本将从新添加的bar4目录创建bar4.jar,而不会对脚本进行任何更改(无硬编码列表)。提前对您有所帮助

回答

2

可以使用subant任务来完成。例如:

<project name="jars" default="jar" basedir="."> 
    <property name="dir.build" value="${basedir}/build"/> 
    <property name="dir.root" value="${basedir}/foo"/> 

    <target name="init"> 
     <tstamp/> 
     <mkdir dir="${dir.build}"/> 
    </target> 

    <target name="jar" depends="init"> 
     <!-- ${ant.file} is the name of the current build file --> 
     <subant genericantfile="${ant.file}" target="do-jar"> 

      <!-- Pass the needed properties to the subant call. You could also use 
       the inheritall attribute on the subant element above to pass all 
       properties. --> 
      <propertyset> 
       <propertyref name="dir.build"/> 
      </propertyset> 

      <!-- subant will call the "do-jar" target for every directory in the 
       ${dir.root} directory, making the subdirectory the basedir. --> 
      <dirset dir="${dir.root}" includes="*"/> 
     </subant> 
    </target> 

    <target name="do-jar"> 
     <!-- Get the basename of the basedir (bar1, bar2, etc.) --> 
     <basename file="${basedir}" property="jarname"/> 

     <jar jarfile="${dir.build}/${jarname}.jar" basedir="${basedir}"/> 
    </target> 
</project> 
0

感谢你可以使用适当的Jar task,与foreach蚂蚁的contrib支线任务一起。

样本:

<foreach list="${hmProjectsList}" delimiter="/," 
     target="cvsCheckOut" param="hmProjectDir" inheritall="true" /> 
+0

Jar在输入单个输出文件中占用多个文件。我需要多个输出文件。如果你知道如何做到这一点,你可以举个例子吗? – dilig0 2009-10-12 12:33:05

+0

对不起。我改编了我的答案。 – KLE 2009-10-12 12:55:17

+0

AFAIK jar任务可以将一个basedir作为输入并将其转换为目标文件 - 这看起来就像您需要的一样。 – 2009-10-13 06:39:05

相关问题