DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Ant 脚本
ant 构架部署web应用脚本
build.properties:
=====================================
appserver.home=d:/tomcat
deploy.path=${appserver.home}/webapps
tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=spring
tomcat.manager.password=spring
=====================================
<?xml version="1.0" encoding="gb2312"?>
<project name="springapp" basedir="." default="usage">
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="extlib.dir" value="lib"/>
<property name="web.dir" value="war"/>
<property name="config.dir" value="config"/>
<property name="class.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="lib.dir" value="${web.dir}/WEB-INF/lib"/>
<property name="name" value="springapp"/>
<path id="master-classpath">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${appserver.name}/common/lib">
<include name="servlet*.jar"/>
</fileset>
<pathelement path="${class.dir}"/>
</path>
<target name="usage" description="脚本包å«çš„坿‰§è¡Œå‘½ä»¤">
<echo message="ã€å¸®åŠ©ä¿¡æ¯ã€‘${name}工程å¯ç”¨å‘½ä»¤ï¼š"/>
<echo message="使用方法:在ant 命令åŽåŠ ä¸‹åˆ—å‘½ä»¤"/>
<echo message=""/>
<echo message="build:-->(编译工程)build the application"/>
<echo message="deploy:-->(å‘布应用)deploy application as directory"/>
<echo message="deploywar:-->(打包æˆwar文件)deploy application as a war file"/>
<echo message="install:-->(将应用安装到tomcat)Install application in tomcat"/>
<echo message="reload:-->ï¼ˆé‡æ–°è£…入应用)reload application in tomcat"/>
<echo message="start:-->(开始tomcat应用)start tomcat application"/>
<echo message="stop:-->ï¼ˆåœæ¢tomcat应用)stop tomcat application"/>
<echo message="list:-->(列表tomcat的应用)list tomcat application"/>
</target>
<!--[åˆå§‹åŒ–]
1.建立目录
2.æ‹·è´å¤–部引用包web-inf/lib
3.æ‹·è´é…置文件(web.xmlç‰)至web-inf
-->
<target name="init">
<mkdir dir="${class.dir}" />
<mkdir dir="${lib.dir}" />
<copy todir="${lib.dir}">
<fileset dir="${extlib.dir}">
<include name="*.jar"/>
</fileset>
</copy>
<copy todir="${web.dir}/WEB-INF">
<fileset dir="${config.dir}">
<include name="web.xml"/>
</fileset>
</copy>
</target>
<!-- [编译程åº] -->
<target name="build" depends="init" description="build the application">
<javac srcdir="${src.dir}" destdir="${class.dir}" debug="true" deprecation="true">
<classpath refid="master-classpath" />
</javac>
<copy todir="${class.dir}">
<fileset dir="${src.dir}">
<include name="**/*.gif" />
<include name="**/*.jpg" />
<include name="**/*.png" />
<include name="**/*.wav" />
<include name="**/*.dtd" />
<include name="**/*.properties" />
</fileset>
</copy>
</target>
<!-- [å‘布目录到tomcat]
1.建立tomcat目录
2.æ‹·è´war目录下所有内容到tomcat目录
-->
<target name="deploy" description="Deploy application to servlet container">
<mkdir dir="${deploy.path}/${name}"/>
<copy todir="${deploy.path}/${name}">
<fileset dir="${web.dir}"/>
</copy>
</target>
<!--[å‘布应用为war包]-->
<target name="deploywar">
<war destfile="${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}"/>
</war>
</target>
<!--[åˆ é™¤tomcat应用]-->
<target name="clean">
<delete dir="${deploy.path}/${name}"/>
</target>
<target name="start">
<java jar="${appserver.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${appserver.home}"/>
<arg line="start"/>
</java>
</target>
<target name="stop">
<java jar="${appserver.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${appserver.home}"/>
<arg line="stop"/>
</java>
</target>
</project>




