public class HelloAnt {
public static void main(String[] args) {
System.out.println("Hello Ant!");
}
}
[출처] ant를 이용하여 컴파일, 배포(*.jar)파일 생성하기.|작성자 짱구
build.xml
<?xml version="1.0" encoding="euc-kr"?>
<project default="main" basedir=".">
<!--
====================================================================
properties: build.xml에서 사용하는 속성값을 설정한다.
====================================================================
-->
<property name="name" value="ex" />
<property name="version" value="1.0" />
<property name="src.dir" value="src" />
<property name="build.dir" value="build" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="jar.file" value="${build.dir}/${name}.jar" />
<property name="dist.dir" value="dist" />
<property name="dist.file" value="${dist.dir}/${name}-${version}" />
<!--
====================================================================
compile 타겟 : java파일을 컴파일한다.
====================================================================
-->
<target name="compile">
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}">
</javac>
</target>
<!--
====================================================================
jars 타겟 : 컴파일한 클래스 파일을 jar로 묶는다.
====================================================================
-->
<target name="jars" depends="compile">
<jar jarfile="${jar.file}" basedir="${classes.dir}">
</jar>
</target>
<!--
====================================================================
distribution 타겟 : 배포본을 만든다.
====================================================================
-->
<target name="dist" depends="jars">
<mkdir dir="${dist.file}" />
<zip destfile="${dist.file}.zip" basedir="${build.dir}" includes="*.jar" />
</target>
<!--
==============================================================================
main 타겟 : 사용자가 타겟을 지정하지 않은 경우, 기본 값으로 지정되는 타겟이다.
==============================================================================
-->
<target name="main" depends="jars" />
<!--
==============================================================================
clean 타겟 : 이전의 컴파일한 클래스 파일과 배포 본을 지운다.
==============================================================================
-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<!--
==============================================================================
all 타겟 : 모든 작업을 수행한다.
==============================================================================
-->
<target name="all" depends="clean, dist" />
</project>