ant的最佳实践笔记

1.ant将struts2+spring3项目打成war包

<?xml version="1.0"?>
 
 <project name="techbirds" default="ftp" basedir=".">
 
 	<property name="techbirds.home" location="E:\Workspaces\MyEclipse 8.5\techbirds" />
 	<property name="techbirds.home.webroot" location="${techbirds.home}\webroot" />
 	<property name="techbirds.src" location="${techbirds.home}/src" />
 	<property name="techbirds.lib" location="${techbirds.home}/WebRoot/WEB-INF/lib" />
 	<property name="techbirds.classes" location="${techbirds.home}/WEB-INF/classes" />
 	<property name="tomcat.home" location="D:\apache-tomcat-6.0.30" />
 
 	<property name="techbirds.build.dir" value="build" />
 	<property name="techbirds.classes.dir" location="${techbirds.build.dir}/classes">
 	</property>
 	<target name="clean">
 		<delete dir="${techbirds.build.dir}" />
 	</target>
 	<target name="init" depends="clean">
 		<path id="all">
 			<fileset dir="${techbirds.lib}">
 				<include name="**/*.jar" />
 			</fileset>
 			<fileset dir="${tomcat.home}/lib">
 				<include name="*.jar" />
 			</fileset>
 		</path>
 		<mkdir dir="${techbirds.build.dir}" />
 		<mkdir dir="${techbirds.classes.dir}" />
 	</target>
 	<target name="compile" depends="init">
 		<javac srcdir="${techbirds.src}" destdir="${techbirds.classes.dir}" target="1.6" includeantruntime="on">
 			<classpath refid="all">
 			</classpath>
 		</javac>
 	</target>
 	<target name="war" depends="compile">
 		<war destfile="${tomcat.home}/techbirds.war" webxml="${techbirds.home}/WebRoot/WEB-INF/web.xml">
 			<fileset dir="${techbirds.home.webroot}">
 				<include name="**/**" />
 				<exclude />
 			</fileset>
 			<lib dir="${techbirds.home}/WebRoot/WEB-INF/lib" />
 			<classes dir="${techbirds.classes.dir}">
 			</classes>
 		</war>
 	</target>
 
 	<target name="ftp" depends="war">
 		<ftp password="xxxx" server="xxxx" userid="admin" action="put" remotedir="techbirds">
 			<fileset dir="${tomcat.home}" includes="*.war">
 			</fileset>
 		</ftp>
 	</target>
 
 </project>

2.ant将多个jar打包成一个jar

<project default="jar">
 	
 	<property name="build.dir" location="build"/>
 	<property name="build.classes.dir" location="${build.dir}/classes"/>
 	
 	<property name="lib.dir" value="lib"/> 	
 	<property name="jar1" value="apache-solr-solrj-3.4.0.jar"></property>
 	<property name="jar2" value="commons-codec-1.4.jar"></property>
 	<property name="jar3" value="commons-httpclient-3.1.jar"></property>
 	<property name="jar4" value="slf4j-log4j12-1.6.1.jar"></property>
 	<property name="jar5" value="slf4j-api-1.6.1.jar"></property>	
 	
 	<property name="jar12345" location="${lib.dir}/webservice.jar"/>  	
 	<property name="file1" location="META-INF"/>
 	<property name="file2" location="${file1}/MANIFEST.MF"/> 	
 	<target name="clean">
 		<delete dir="${build.dir}"></delete>
 	</target>
 
 	<target name="init" depends="clean">
 		<mkdir dir="${build.dir}"/>
 		<mkdir dir="${build.classes.dir}"/>
 	</target>
 
 	<target name="unzip" depends="init">
 		<unzip src="${lib.dir}/${jar1}" dest="${build.classes.dir}/jar1">
 			<patternset>
 				<exclude name="${file1}"/>
 				<exclude name="${file2}"/>
 			</patternset>
 		</unzip>
 		<unzip src="${lib.dir}/${jar2}" dest="${build.classes.dir}/jar2">
 			<patternset>
 				<exclude name="${file1}"/>
 				<exclude name="${file2}"/>
 			</patternset>
 		</unzip>
 		<unzip src="${lib.dir}/${jar3}" dest="${build.classes.dir}/jar3">
 			<patternset>
 				<exclude name="${file1}"/>
 				<exclude name="${file2}"/>
 			</patternset>
 		</unzip>
 		<unzip src="${lib.dir}/${jar4}" dest="${build.classes.dir}/jar4">
 			<patternset>
 				<exclude name="${file1}"/>
 				<exclude name="${file2}"/>
 			</patternset>
 		</unzip>
 		<unzip src="${lib.dir}/${jar5}" dest="${build.classes.dir}/jar5">
 			<patternset>
 				<exclude name="${file1}"/>
 				<exclude name="${file2}"/>
 			</patternset>
 		</unzip>
 	</target>
 	
 	<target name="jar" depends="unzip">
 		<jar jarfile="${jar12345}">
 			<fileset dir="${build.classes.dir}/jar1" includes="**/*.class"></fileset>
 			<fileset dir="${build.classes.dir}/jar2" includes="**/*.class"></fileset>
 			<fileset dir="${build.classes.dir}/jar3" includes="**/*.class"></fileset>
 			<fileset dir="${build.classes.dir}/jar4" includes="**/*.class"></fileset>
 			<fileset dir="${build.classes.dir}/jar5" includes="**/*.class"></fileset>
 		</jar>
 	</target>
 
 </project>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值