■ ant
* 別ファイルに記述したタスクを呼び出すことができる ⇒サンプルの「<ant inheritAll="false" antfile="build_tomcat.xml" target="stop_tomcat" />」部分。
仕様
http://www.jajakarta.org/ant/ant-1.6.1/docs/ja/manual/CoreTasks/ant.htmlサンプル
http://blogs.yahoo.co.jp/dk521123/34057119.htmlより抜粋(一部、修正)
build.xml
<?xml version="1.0" encoding="UTF-8"?> <project basedir="." default="start_tomcat" name="SampleService"> <!-- Tomcat起動 --> <target name="start_tomcat" depends="deploy"> <ant inheritAll="false" antfile="build_tomcat.xml" target="start_tomcat" /> </target> <!-- Tomcat停止 --> <target name="stop_tomcat" depends="start_tomcat"> <ant inheritAll="false" antfile="build_tomcat.xml" target="stop_tomcat" /> </target> </project>
build_tomcat.xml
<?xml version="1.0" encoding="UTF-8"?> <project basedir="." default="start_tomcat" name="Tomcat"> <!-- 環境変数から読み込み --> <property environment="env" /> <echo message="TOMCAT_HOME=${env.TOMCAT_HOME}"/> <property name="tomcat.bin" value="${env.TOMCAT_HOME}/bin" /> <!-- Tomcat起動 --> <target name="start_tomcat"> <exec executable="${tomcat.bin}\startup.bat" /> </target> <!-- Tomcat停止 --> <target name="stop_tomcat"> <exec executable="${tomcat.bin}\shutdown.bat" /> </target> </project>
■ antcall
* 他のターゲットを呼び出す
サンプル
build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project basedir="." default="main" name="SampleCodes"> <target name="main" description=""> <antcall target="callSub"> <param name="args1" value="Mike"/> <param name="args2" value="callSub"/> </antcall> </target> <target name="callSub" description="Sub"> <echo message="Hello World, ${args1}! from ${args2}." /> </target> </project>
■ macrodef
* 新しいタスク(マクロ)を定義
参考文献
http://blog.livedoor.jp/saitotetsuya/archives/13232002.htmlhttp://qiita.com/opengl-8080/items/ccb55bb445de8aca7cca
■ import
* 他のビルドファイルを継承できる あんまり自分では使わなそう。。。
サンプル
parent_build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project basedir="." default="a" name="parent_build"> <target name="a" depends="b" description=""> <echo message="Hello a from parent_build.xml." /> </target> <target name="b" description=""> <echo message="Hello b from parent_build.xml." /> </target> </project>
child_build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project basedir="." default="a" name="child_build"> <import file="parent_build.xml" /> <target name="b" description=""> <echo message="Hello b from child_build.xml." /> </target> </project>
出力結果
b: [echo] Hello b from child_build.xml. a: [echo] Hello a from parent_build.xml. BUILD SUCCESSFUL Total time: 339 milliseconds
参考文献
http://frmmpgit.blog.fc2.com/blog-entry-82.html* API仕様http://www.jajakarta.org/ant/ant-1.6.1/docs/ja/manual/CoreTasks/import.html
関連記事
Antビルドにより、CSVファイルからJavaファイルを自動生成する
* antcall を使った例http://blogs.yahoo.co.jp/dk521123/33914928.html