ant 打包源码

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

<?xml version="1.0"?>  
  1.    
  2.  <project name="techbirds" default="ftp" basedir=".">  
  3.    
  4.     <property name="techbirds.home" location="E:\Workspaces\MyEclipse 8.5\techbirds" />  
  5.     <property name="techbirds.home.webroot" location="${techbirds.home}\webroot" />  
  6.     <property name="techbirds.src" location="${techbirds.home}/src" />  
  7.     <property name="techbirds.lib" location="${techbirds.home}/WebRoot/WEB-INF/lib" />  
  8.     <property name="techbirds.classes" location="${techbirds.home}/WEB-INF/classes" />  
  9.     <property name="tomcat.home" location="D:\apache-tomcat-6.0.30" />  
  10.    
  11.     <property name="techbirds.build.dir" value="build" />  
  12.     <property name="techbirds.classes.dir" location="${techbirds.build.dir}/classes">  
  13.     </property>  
  14.     <target name="clean">  
  15.         <delete dir="${techbirds.build.dir}" />  
  16.     </target>  
  17.     <target name="init" depends="clean">  
  18.         <path id="all">  
  19.             <fileset dir="${techbirds.lib}">  
  20.                 <include name="**/*.jar" />  
  21.             </fileset>  
  22.             <fileset dir="${tomcat.home}/lib">  
  23.                 <include name="*.jar" />  
  24.             </fileset>  
  25.         </path>  
  26.         <mkdir dir="${techbirds.build.dir}" />  
  27.         <mkdir dir="${techbirds.classes.dir}" />  
  28.     </target>  
  29.     <target name="compile" depends="init">  
  30.         <javac srcdir="${techbirds.src}" destdir="${techbirds.classes.dir}" target="1.6" includeantruntime="on">  
  31.             <classpath refid="all">  
  32.             </classpath>  
  33.         </javac>  
  34.     </target>  
  35.     <target name="war" depends="compile">  
  36.         <war destfile="${tomcat.home}/techbirds.war" webxml="${techbirds.home}/WebRoot/WEB-INF/web.xml">  
  37.             <fileset dir="${techbirds.home.webroot}">  
  38.                 <include name="**/**" />  
  39.                 <exclude />  
  40.             </fileset>  
  41.             <lib dir="${techbirds.home}/WebRoot/WEB-INF/lib" />  
  42.             <classes dir="${techbirds.classes.dir}">  
  43.             </classes>  
  44.         </war>  
  45.     </target>  
  46.    
  47.     <target name="ftp" depends="war">  
  48.         <ftp password="xxxx" server="xxxx" userid="admin" action="put" remotedir="techbirds">  
  49.             <fileset dir="${tomcat.home}" includes="*.war">  
  50.             </fileset>  
  51.         </ftp>  
  52.     </target>  
  53.    
  54.  </project>  
<?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

  1. <project default="jar">  
  2.       
  3.     <property name="build.dir" location="build"/>  
  4.     <property name="build.classes.dir" location="${build.dir}/classes"/>  
  5.       
  6.     <property name="lib.dir" value="lib"/>      
  7.     <property name="jar1" value="apache-solr-solrj-3.4.0.jar"></property>  
  8.     <property name="jar2" value="commons-codec-1.4.jar"></property>  
  9.     <property name="jar3" value="commons-httpclient-3.1.jar"></property>  
  10.     <property name="jar4" value="slf4j-log4j12-1.6.1.jar"></property>  
  11.     <property name="jar5" value="slf4j-api-1.6.1.jar"></property>     
  12.       
  13.     <property name="jar12345" location="${lib.dir}/webservice.jar"/>        
  14.     <property name="file1" location="META-INF"/>  
  15.     <property name="file2" location="${file1}/MANIFEST.MF"/>    
  16.     <target name="clean">  
  17.         <delete dir="${build.dir}"></delete>  
  18.     </target>  
  19.    
  20.     <target name="init" depends="clean">  
  21.         <mkdir dir="${build.dir}"/>  
  22.         <mkdir dir="${build.classes.dir}"/>  
  23.     </target>  
  24.    
  25.     <target name="unzip" depends="init">  
  26.         <unzip src="${lib.dir}/${jar1}" dest="${build.classes.dir}/jar1">  
  27.             <patternset>  
  28.                 <exclude name="${file1}"/>  
  29.                 <exclude name="${file2}"/>  
  30.             </patternset>  
  31.         </unzip>  
  32.         <unzip src="${lib.dir}/${jar2}" dest="${build.classes.dir}/jar2">  
  33.             <patternset>  
  34.                 <exclude name="${file1}"/>  
  35.                 <exclude name="${file2}"/>  
  36.             </patternset>  
  37.         </unzip>  
  38.         <unzip src="${lib.dir}/${jar3}" dest="${build.classes.dir}/jar3">  
  39.             <patternset>  
  40.                 <exclude name="${file1}"/>  
  41.                 <exclude name="${file2}"/>  
  42.             </patternset>  
  43.         </unzip>  
  44.         <unzip src="${lib.dir}/${jar4}" dest="${build.classes.dir}/jar4">  
  45.             <patternset>  
  46.                 <exclude name="${file1}"/>  
  47.                 <exclude name="${file2}"/>  
  48.             </patternset>  
  49.         </unzip>  
  50.         <unzip src="${lib.dir}/${jar5}" dest="${build.classes.dir}/jar5">  
  51.             <patternset>  
  52.                 <exclude name="${file1}"/>  
  53.                 <exclude name="${file2}"/>  
  54.             </patternset>  
  55.         </unzip>  
  56.     </target>  
  57.       
  58.     <target name="jar" depends="unzip">  
  59.         <jar jarfile="${jar12345}">  
  60.             <fileset dir="${build.classes.dir}/jar1" includes="**/*.class"></fileset>  
  61.             <fileset dir="${build.classes.dir}/jar2" includes="**/*.class"></fileset>  
  62.             <fileset dir="${build.classes.dir}/jar3" includes="**/*.class"></fileset>  
  63.             <fileset dir="${build.classes.dir}/jar4" includes="**/*.class"></fileset>  
  64.             <fileset dir="${build.classes.dir}/jar5" includes="**/*.class"></fileset>  
  65.         </jar>  
  66.     </target>  
  67.    
  68.  </project>  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值