Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ant Buildサンプル

■概要
AntのBuildサンプルを紹介。

■前提

  • 配置ファイル

build.xml
Ant.java

  • ファイル名を指定しないでantを実行する場合、デフォルトでbuild.xmlが実行される
  • build.xml中身
<?xml version="1.0" ?>
<project name="antBuild" default="main">
	<target name="main" depends="clear, compile, compress">
		<echo>Building the .jar file</echo>
	</target>
	<target name="clear" description="前回ビルド結果ファイルを削除">
		<delete file="Ant.class" />
		<delete file="Project.jar" />
	</target>
	<target name="compile" description="コンパイル">
		<javac srcdir="." includeantruntime="false" />
	</target>
	<target name="compress" description="圧縮">
		<jar jarfile="Project.jar" basedir="." includes="*.class" />
	</target>
</project>
  • build.xml中身について
    • echo = dosのechoコマンドと同様
    • delete = dosのdeleteコマンドと同様
    • javac = javacの実行
    • jar = jarコマンドの実行
  • 実行時コンソール出力内容
C:\antSample>ant
Buildfile: C:\antSample\build.xml

clear:
   [delete] Deleting: C:\antSample\Ant.class
   [delete] Deleting: C:\antSample\Project.jar

compile:
    [javac] Compiling 1 source file

compress:
      [jar] Building jar: C:\antSample\Project.jar

main:
     [echo] Building the .jar file

BUILD SUCCESSFUL
Total time: 0 seconds
  • 実行結果ファイル

Ant.class
Ant.java
build.xml
Project.jar