2009-10-12 8 views
1

디렉토리 목록을 .jar 파일 목록으로 변환하는 방법은 무엇입니까? Copy Task와 Mappers를 사용하는 것이 올바른 방법이지만 디렉토리에서 jar 파일을 만드는 중첩 요소를 찾지 못했을 것 같습니다.Ant를 사용하여 .jar 파일로 디렉토리를 변환하는 방법

물론 디렉토리 목록은 계산되어 ant 스크립트에 하드 코딩되지 않았습니다.

예를 들어 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

에 대한 당신은 foreach 개미의 contrib 확장 작업과 함께 적절한 Jar task를 사용할 수 있습니다.

샘플은 :

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

Jar는 입력, 단일 출력 파일에서 여러 파일을 사용합니다. 출력 파일이 여러 개 필요합니다. 이 작업을 수행하는 방법을 알고 있다면 예제를 줄 수 있습니까? – dilig0

+0

죄송합니다. 나는 나의 대답에 적응했다. – KLE

+0

AFAIK jar 작업은 기반 디렉토리를 입력으로 가져 와서 대상 파일로 변환 할 수 있습니다. –

관련 문제