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>