<!-- dist target은 compile에의존.
compile target 실행 후에 dist target이 실행된다. -->
...
</target>
<targetname="doc">
...
</target>
</project>
※ 예제 :
test1과 test2 패키지를 test1_2.jar 파일로 묶고,
test2와 test3 패키지를 묶어 test2_3.jar 파일로 묶는다.
javadoc 을 만들고,
lib폴더와 jar 파일들을 zip으로 묶는다.
<projectname="ant"default="test1_2"basedir=".">
<tstamp/>
<!-- property -->
<propertyname="src"location="src"/>
<propertyname="build"location="build"/>
<propertyname="lib"location="lib"/>
<propertyname="dist"location="dist"/>
<propertyname="doc"location="doc"/>
<!-- compile -->
<targetname="compile"description="compile">
<mkdirdir="${build}"/>
<javacsrcdir="${src}"destdir="${build}"
classpath="${lib}/log4j-1.2.8.jar"/>
</target>
<!-- test1과 test2를 jar로묶는다 -->
<targetname="test1_2"depends="compile"
description="test1 and test2 packaging">
<mkdirdir="${dist}"/>
<jarjarfile="${dist}/test1_2.${DSTAMP}.jar">
<filesetdir="${build}">
<excludename="test3/*.*"/>
</fileset>
</jar>
</target>
<!-- test2과 test3를 jar로묶는다 -->
<targetname="test2_3"depends="compile"
description="test2 and test3 packaging">
<mkdirdir="${dist}"/>
<jarjarfile="${dist}/test2_3.${DSTAMP}.jar">
<filesetdir="${build}">
<excludename="test1/*.*"/>
</fileset>
</jar>
</target>
<!-- doc -->
<targetname="doc"depends="test1_2, test2_3">
<mkdirdir="${doc}"/>
<javadocdestdir="${doc}">
<filesetdir="${src}"/>
</javadoc>
</target>
<!-- zip -->
<targetname="zip"depends="test1_2, test2_3">
<copytodir="${dist}/lib">
<filesetdir="${lib}"/>
</copy>
<zipdestfile="test_${DSTAMP}.zip">
<filesetdir="${dist}"/>
</zip>
</target>
<!-- delete -->
<targetname="delete"depends="doc, zip">
<deletedir="${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는 여러 개 가능하다.
Java 기반의 build 도구로서, file 형식은 XML 이다.
make 와는 달리 플랫폼 독립적인 Java 클래스를 사용하기 때문에 OS에 독립적이다.
이클립스는 Ant 플러그인을 기본으로 내장하므로 따로 설치할 필요 없다.
★ build.xml 생성
← 왼쪽과 같이 파일이 존재한다고 가정한다.
프로젝트(ant)를 선택하고 컨텍스트 메뉴에서 New > File 을 선택한다.
↓ 아래와 같은 창이 뜨면
File Name 에 build.xml 을 입력한다.
자동으로 ant 파일로 인식되어 Package Explorer 에 ant 파일로 표시된다.
(Window > Preference 에서 좌측 Ant 선택, 우측의 Names 에 build.xml 이 있다. 여기에 ,abc.xml 이런식으로 추가입력하면 abc.xml 파일 생성시 ant 파일로 인식된다.)
← 개미 모양의 build.xml 파일을 볼 수 있을 것이다.
↓ 에디터 창에서 파일을 작성한 후,
Outline View 를 보면 아래와 같이 나타난다.
ant 를 클릭하고 컨텍스트 메뉴에서 Run As를 클릭한다.
Ant Build는 default로 지정된 target이 실행된다.
Ant Build... 를 선택하면 다이얼로그 창이 뜬다.
↑ Ant Build... 을 선택했을 때의 다이얼로그.
(클릭하면 제대로 된 그림을 볼 수 있을 것이다.)
target name 앞에 체크 박스를 선택하는 순서대로 실행된다.
아랫부분의 Target execution order 란에 선택한 순서대로 표시된다.
순서를 바꾸고 싶으면 체크를 해제한 후 다시 선택하거나,
우측의 Order 버튼을 선택해 위 아래로 위치를 변경하면 된다.
중간에
Sort targets : 체크시, target name이 알파벳 순서대로 정렬된다.
Hide Internal Targets not selected for execution :
Hide Internal Targets 는 description이 없는 타깃을 말한다.
그러므로 체크하면 description이 없는 타깃은 목록에서 사라진다.