---
title: "Ant构建文件"
author: "majm"
date: "2011-08-11T23:59:30Z"
tags: []
categories: ["编程语言"]
slug: "ant"
draft: false
lastmod: "2012-03-29T07:54:17Z"
id: 1146907
url: "https://majm.iteye.com/blog/1146907"
---

示例项目目录结构
src	代码源文件
test 单元测试代码
lib 依赖文件
build 构建过程中生成的任何文件
build/classes 编译好的java类
build/test-classes 编译好的单元测试类
dist 打包文件

war文件的典型目录结构
/ 可以公开访问的网页
/WEB-INF/ 配置文件从网站上不可见
/WEB-INF/classes 编译的的类
WEB-INF/lib 应用程序库

<target name="clean" depends="init" description="Deletes generated directories">

使用-f来指定不同的文件。
ant -f my-buildfile.xml

查看构建目标
ant -projecthelp

只需要指定编译的目录
<javac srcdir="src" destdir="build/classes" includes="com/huawe/**" />

应用程序打包
<war destfile="${dist.dir}/${project.name}-${project.version}.war" webxml=$(web.dir)/WEB-INF/web.xml>
	<fileset dir="${web.dir}"/>
	<classes dir="${build.classes.dir}"/ >
	<lib dir="${lib}">
		<include name="**.jar">
	</lib>
</war>

部署应程序
复制文件
<property name="tomcat.install.dir" localtion="${user.home}/servers/tomcat">
<target name="local.deploy" depends="war" description="Deploy to local Tomcat instance">
	<copy file="${dist.dir}/${project.name}-${project.version}.war"
				tofile="${tomcat.install.dir}/webapps/${project.name}.war"/>
</target>

<target name="remote.deploy" depends="war" description="">
	<scp file="${dist.dir}/${project.name}-${project.version}.war"
				todir="omu@serverIP:/home/integration/tomcatbase/webapps"
				password="omu" />
</target>