Ant-packaging-applications
提供:Dev Guides
Ant-パッケージングアプリケーション
*Hello World* Fax Webアプリケーションを少しずつ使用して、Antのさまざまな側面を学びました。
ここで、すべてをまとめて完全で完全なbuild.xmlファイルを作成します。 次のように build.properties と build.xml ファイルを考慮してください-
build.properties
deploy.path = c:\tomcat6\webapps
build.xml
<?xml version = "1.0"?>
<project name = "fax" basedir = "." default = "usage">
<property file = "build.properties"/>
<property name = "src.dir" value = "src"/>
<property name = "web.dir" value = "war"/>
<property name = "javadoc.dir" value = "doc"/>
<property name = "build.dir" value = "${web.dir}/WEB-INF/classes"/>
<property name = "name" value = "fax"/>
<path id = "master-classpath">
<fileset dir = "${web.dir}/WEB-INF/lib">
<include name = "*.jar"/>
</fileset>
<pathelement path = "${build.dir}"/>
</path>
<target name = "javadoc">
<javadoc packagenames = "faxapp.*" sourcepath = "${src.dir}"
destdir = "doc" version = "true" windowtitle = "Fax Application">
<doctitle><![CDATA[<h1> = Fax Application = </h1>]]>
</doctitle>
<bottom><![CDATA[Copyright © 2011. All Rights Reserved.]]>
</bottom>
<group title = "util packages" packages = "faxapp.util.*"/>
<group title = "web packages" packages = "faxapp.web.*"/>
<group title = "data packages" packages = "faxapp.entity.*:faxapp.dao.*"/>
</javadoc>
</target>
<target name = "usage">
<echo message = ""/>
<echo message = "${name} build file"/>
<echo message = "-----------------------------------"/>
<echo message = ""/>
<echo message = "Available targets are:"/>
<echo message = ""/>
<echo message = "deploy --> Deploy application as directory"/>
<echo message = "deploywar --> Deploy application as a WAR file"/>
<echo message = ""/>
</target>
<target name = "build" description = "Compile main source tree java files">
<mkdir dir = "${build.dir}"/>
<javac destdir = "${build.dir}" source = "1.5" target = "1.5" debug = "true"
deprecation = "false" optimize = "false" failonerror = "true">
<src path = "${src.dir}"/>
<classpath refid = "master-classpath"/>
</javac>
</target>
<target name = "deploy" depends = "build" description = "Deploy application">
<copy todir = "${deploy.path}/${name}" preservelastmodified = "true">
<fileset dir = "${web.dir}">
<include name = "**/*.*"/>
</fileset>
</copy>
</target>
<target name = "deploywar" depends = "build" description =
"Deploy application as a WAR file">
<war destfile = "${name}.war" webxml = "${web.dir}/WEB-INF/web.xml">
<fileset dir = "${web.dir}">
<include name = "**/*.*"/>
</fileset>
</war>
<copy todir = "${deploy.path}" preservelastmodified = "true">
<fileset dir = ".">
<include name = "*.war"/>
</fileset>
</copy>
</target>
<target name = "clean" description = "Clean output directories">
<delete>
<fileset dir = "${build.dir}">
<include name = "**/*.class"/>
</fileset>
</delete>
</target>
</project>
この例では-
- まず、ビルドプロパティファイルでTomcatのwebappsフォルダーへのパスを deploy.path 変数として宣言します。
- また、 src.dir 変数でjavaファイルのソースフォルダーを宣言します。
- 次に、 web.dir 変数でWebファイルのソースフォルダーを宣言します。 javadoc.dir はJavaドキュメントを保存するためのフォルダーです。 build.dir はビルド出力ファイルを保存するためのパスです。
- 次に、Webアプリケーションの名前を宣言します。この例では fax です。
- また、プロジェクトのWEB-INF/libフォルダーにあるJARファイルを含むマスタークラスパスを定義します。
- また、マスタークラスパスの build.dir にあるクラスファイルも含めます。
- Javadocターゲットは、プロジェクトに必要なjavadocを生成し、使用ターゲットは、ビルドファイルに存在する一般的なターゲットを印刷するために使用されます。
上記の例は、 deploy と* deploywar。*の2つの展開ターゲットを示しています。
展開ターゲットは、ファイルをWebディレクトリから展開ディレクトリにコピーし、最終変更日時スタンプを保持します。 これは、ホットデプロイメントをサポートするサーバーにデプロイするときに役立ちます。
cleanターゲットは、以前にビルドされたすべてのファイルをクリアします。
deploywarターゲットはwarファイルをビルドしてから、warファイルをアプリケーションサーバーのdeployディレクトリにコピーします。