Apache Ant 1.7.0 Manual : http://ant.apache.org/manual/
Ant 기본구조 및 태스크는 아래 블로그를 참조하자.
잘 정리되어 있는 듯...
Ant 자바 빌드 툴 I : 기본 구조 : http://blog.naver.com/thdusin/100005914122
Ant 자바 빌드 툴 II : 태스크 : http://blog.naver.com/thdusin/100005926620
더 자세한 task를 알고 싶다면 apache 사이트를 참조하자.
Overview of Ant Tasks : http://ant.apache.org/manual/tasksoverview.html
build.xml 은 하나의 project 요소를 가진다.
project 요소는 target 요소를 포함하고, 각 target은 여러 task를 포함한다.
간단한 구조는 다음과 같다.
<project name="project_name" default="default" basedir=".">
       <target name="compile" description="compile">
       <!--compile이라는 target name에 대한 설명(description)-->
             ...
       </target>
       
       <target name="dist" depends="compile">
       <!-- dist target은 compile에 의존. 
       compile target 실행 후에 dist target이 실행된다. -->
             ...
       </target>
       <target name="doc">
             ...
       </target>
</project>   
※ 예제 :
test2와 test3 패키지를 묶어 test2_3.jar 파일로 묶는다.
javadoc 을 만들고,
lib폴더와 jar 파일들을 zip으로 묶는다.
<project name="ant" default="test1_2" basedir=".">
       
       <tstamp/>
       <!-- property -->
       <property name="src" location="src"/>
       <property name="build" location="build"/>
       <property name="lib" location="lib"/>
       <property name="dist" location="dist"/>
       <property name="doc" location="doc"/>
             
       <!-- compile -->
       <target name="compile" description="compile">
             <mkdir dir="${build}"/>
             <javac srcdir="${src}" destdir="${build}"
                classpath="${lib}/log4j-1.2.8.jar"/>
       </target>
       
       <!-- test1과 test2를 jar로 묶는다 -->
       <target name="test1_2" depends="compile" 
             description="test1 and test2 packaging">
             <mkdir dir="${dist}"/>
             <jar jarfile="${dist}/test1_2.${DSTAMP}.jar">
                    <fileset dir="${build}">
                           <exclude name="test3/*.*"/>
                    </fileset>
             </jar>
       </target>
       
       <!-- test2과 test3를 jar로 묶는다 -->
       <target name="test2_3" depends="compile"
             description="test2 and test3 packaging">
             <mkdir dir="${dist}"/>
             <jar jarfile="${dist}/test2_3.${DSTAMP}.jar">
                    <fileset dir="${build}">
                           <exclude name="test1/*.*"/>
                    </fileset>
             </jar>
       </target>
       
       <!-- doc -->
       <target name="doc" depends="test1_2, test2_3">
             <mkdir dir="${doc}"/>
             <javadoc destdir="${doc}">
                    <fileset dir="${src}"/>
             </javadoc>
       </target>
       
       <!-- zip -->
       <target name="zip" depends="test1_2, test2_3">
             <copy todir="${dist}/lib">
                    <fileset dir="${lib}"/>
             </copy>
            
 <zip destfile="test_${DSTAMP}.zip">
                    <fileset dir="${dist}"/>
             </zip>
       </target>
       
       <!-- delete -->
       <target name="delete" depends="doc, zip">
             <delete dir="${build}"/>
       </target>
       
</project>
※ 설명 :
<!-- project -->
그냥 Run As 했을 경우, default 로 설정된 target이 실행된다.
default : Run as 시, 기본적으로 사용할 target name
basedir : base directory. 현재 디렉터리(.)이다.
<!-- property -->
property : 속성을 지정한다. 대소문자 구별.
<property name="src" location="src" />
src 라는 이름의 속성으로 경로(./src)를 지정한다.
다른 부분에서 이 속성을 참조하려면 "${src}" 라고 쓴다.
<javac srcdir="${src}" destdir="${build}" />
( value 와 location )
value : the value of the property.
location : Sets the property to the absolute filename of the given file. If the value of this attribute is an absolute path, it is left unchanged (with / and \ characters converted to the current platforms conventions). Otherwise it is taken as a path relative to the project's basedir and expanded.
<!-- compile -->
<mkdir dir="${build}"/>
build 라는 디렉터리를 만든다.
<javac srcdir="${src}" destdir="${build}" classpath="${lib}/log4j-1.2.8.jar"/>
src 디렉터리(하위 디렉터리 포함)의 java 파일을 컴파일해 build 디렉터리에 저장하고,
클래스패스에는 log4j-1.2.8.jar가 포함된다.
<!-- test1과 test2를 jar로 묶는다 -->
<jar jarfile="${dist}/test1_2.${DSTAMP}.jar">
<fileset dir="${build}">
<exclude name="test3/*.*"/>
</fileset>
</jar>
property 윗부분에 <tstamp/> 가 있다.
이는 DSTAMP, TSTAMP, TODAY 프로퍼티를 설정하는 것이다.
· DSTAMP : yyyyMMdd
· TSTAMP : hhmm
· TODAY : MMM dd yyy
build 디렉터리에서 test3 패키지의 파일들을 제외(exclude)한 파일들을 jar로 묶어
dist 에 test1_2.날짜.jar 형태로 저장한다.
(ex. test1_2.20070802.jar)
fileset dir 하의 include, exclude는 여러 개 가능하다.
<!-- doc -->
<javadoc destdir="${doc}">
<fileset dir="${src}"/>
</javadoc>
src 디렉터리의 파일들을 읽어 javadoc문서를 만들어 doc 디렉터리에 저장한다.
<!-- zip -->
<copy todir="${dist}/lib">
<fileset dir="${lib}"/>
</copy>
lib 디렉터리를 dist/lib 에 복사한다.
<zip destfile="test_${DSTAMP}.zip">
<fileset dir="${dist}"/>
</zip>
dist 디렉터리의 파일들을 zip으로 묶는다.
zip 파일이름은 test_날짜.zip (ex. test_20070802.zip)
<!-- delete -->
<delete dir="${build}"/>
build 디렉터리를 삭제한다.
※ 결과 :
compile:
    [mkdir] Created dir: C:\Users\kyh\workspace\ant\ant\build
    [javac] Compiling 4 source files to C:\Users\kyh\workspace\ant\ant\build
test1_2:
    [mkdir] Created dir: C:\Users\kyh\workspace\ant\ant\dist
      [jar] Building jar: C:\Users\kyh\workspace\ant\ant\dist\test1_2.20070802.jar
compile:
test1_2:
test2_3:
      [jar] Building jar: C:\Users\kyh\workspace\ant\ant\dist\test2_3.20070802.jar
doc:
    [mkdir] Created dir: C:\Users\kyh\workspace\ant\ant\doc
  [javadoc] Generating Javadoc
  [javadoc] Javadoc execution
  [javadoc] Loading source file C:\Users\kyh\workspace\ant\ant\src\test1\AntTest.java...
  [javadoc] Loading source file C:\Users\kyh\workspace\ant\ant\src\test2\AntTest2.java...
  [javadoc] Loading source file C:\Users\kyh\workspace\ant\ant\src\test2\AntTest2_1.java...
  [javadoc] Loading source file C:\Users\kyh\workspace\ant\ant\src\test3\AntTest3.java...
  [javadoc] Constructing Javadoc information...
  [javadoc] Standard Doclet version 1.6.0_02
  [javadoc] Building tree for all the packages and classes...
  [javadoc] Building index for all the packages and classes...
  [javadoc] Building index for all classes...
zip:
     [copy] Copying 1 file to C:\Users\kyh\workspace\ant\ant\dist\lib
      [zip] Building zip: C:\Users\kyh\workspace\ant\ant\test_20070802.zip
delete:
   [delete] Deleting directory C:\Users\kyh\workspace\ant\ant\build
BUILD SUCCESSFUL
Total time: 2 seconds


 
 
