`

完整ant自动编译打包和发布脚本

阅读更多
xml 代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <project basedir="." default="build" name="potato">  
  4.     <property file="ant.properties"/>  
  5.     <property environment="env"/>  
  6.     <property name="tomcat.path" value="${tomcat.path}"/>  
  7.     <echo message="tomcat.path = ${tomcat.path}"/>  
  8.            
  9.     <property name="websrc.dir" value="WebContent"/>  
  10.     <property name="src.dir" value="src"/>  
  11.     <property name="build.dir" value="build"/>  
  12.     <property name="dist.dir" value="dist"/>  
  13.     <property name="deploy.dir" value="${tomcat.path}/webapps"/>  
  14.     <property name="dest.jar" value="potato.jar"/>  
  15.     <property name="dest.war" value="potato.war"/>  
  16.     <property name="jdk.source" value="1.5"/>  
  17.     <property name="jdk.target" value="1.5"/>  
  18.     <property name="src.zipfile" value="potato.zip"/>  
  19.     <property name="build.out" value="${build.dir}/WEB-INF/classes" />  
  20.     <property name="dest.zip" value="potato.zip" />  
  21.     <property name="deploy.web.dir" value="potato" />      
  22.            
  23.        
  24.     <patternset id="jar.pattern"><include name="**/*.jar"/></patternset>  
  25.     <patternset id="config.pattern">  
  26.         <include name="**/*.xml"/>  
  27.         <include name="**/*.properties"/>  
  28.         <include name="**/*.prop"/>  
  29.         <include name="**/*.conf"/>  
  30.         <include name="**/*.tld"/>  
  31.         <include name="**/*.ftl"/>  
  32.     </patternset>  
  33.     <path id="compile.classpath">  
  34.         <fileset dir="${tomcat.path}/common/lib">  
  35.             <patternset refid="jar.pattern"/>  
  36.         </fileset>  
  37.         <fileset dir="${websrc.dir}/WEB-INF/lib">  
  38.             <patternset refid="jar.pattern"/>  
  39.         </fileset>  
  40.     </path>  
  41.        
  42.     <patternset id="build.pattern">  
  43.       <include name="**/*.jar"/>  
  44.       <include name="**/*.class"/>  
  45.       <include name="**/*.xml"/>  
  46.       <include name="**/*.properties"/>  
  47.       <include name="**/*.prop"/>  
  48.       <include name="**/*.conf"/>  
  49.       <include name="**/*.tld"/>  
  50.       <include name="**/*.ftl"/>  
  51.       <include name="**/*.jsp"/>  
  52.       <include name="**/*.htm"/>  
  53.       <include name="**/*.html"/>  
  54.       <include name="**/*.js"/>  
  55.       <include name="**/*.css"/>  
  56.       <include name="**/*.swf"/>  
  57.       <include name="**/*.jpg"/>  
  58.       <include name="**/*.gif"/>  
  59.       <include name="**/*.png"/>  
  60.       <include name="**/*.rar"/>  
  61.       <include name="**/*.wmv"/>  
  62.       <include name="**/*.mp3"/>  
  63.       <include name="**/*.3gp"/>  
  64.       <include name="**/*.doc"/>  
  65.       <exclude name="WEB-INF/**/*"/>  
  66.       <exclude name="**/web.xml"/>  
  67.     </patternset>  
  68.     <patternset id="src.pattern">  
  69.       <include name="**/*.java"/>  
  70.       <include name="**/*.xml"/>  
  71.       <include name="**/*.properties"/>  
  72.       <include name="**/*.prop"/>  
  73.       <include name="**/*.conf"/>  
  74.       <include name="**/*.tld"/>  
  75.       <include name="**/*.ftl"/>  
  76.       <include name="**/*.jsp"/>  
  77.       <include name="**/*.htm"/>  
  78.       <include name="**/*.html"/>  
  79.       <include name="**/*.js"/>  
  80.       <include name="**/*.css"/>  
  81.       <include name="**/*.swf"/>  
  82.       <include name="**/*.jpg"/>  
  83.       <include name="**/*.gif"/>  
  84.       <include name="**/*.png"/>  
  85.       <exclude name="**/web.xml"/>  
  86.     </patternset>  
  87.   
  88.     <tstamp>  
  89.         <format property="date.current" pattern="yyyyMMdd"/>  
  90.         <format property="time.current" pattern="HHmmss"/>  
  91.     </tstamp>  
  92.   
  93.     <target name="clean">  
  94.         <delete dir="${build.dir}"/>  
  95.         <delete dir="${dist.dir}"/>  
  96.         <!--delete file="${dist.dir}/${dest.war}" /-->  
  97.     </target>  
  98.        
  99.     <target name="init">  
  100.         <mkdir dir="${build.dir}"/>  
  101.         <mkdir dir="${build.dir}/classes"/>  
  102.         <mkdir dir="${dist.dir}"/>  
  103.         <mkdir dir="${build.out}"/>  
  104.     </target>  
  105.        
  106.     <target name="compile" depends="init">  
  107.         <javac srcdir="${src.dir}" destdir="${build.dir}/classes" debug="true">  
  108.             <classpath refid="compile.classpath" />  
  109.         </javac>  
  110.         <copy todir="${build.dir}/classes">  
  111.             <fileset dir="${src.dir}">  
  112.                 <patternset refid="config.pattern"/>  
  113.             </fileset>  
  114.         </copy>  
  115.     </target>  
  116.   
  117.     <!-- deploy complie-->  
  118.     <target name="deploycompile" depends="init">  
  119.         <copy todir="${build.dir}">  
  120.             <fileset dir="${websrc.dir}">  
  121.                 <exclude name="**/*.java" />  
  122.                 <exclude name="**/servlet-api.jar" />  
  123.                 <exclude name="resource/**/*"/>  
  124.                 <exclude name="images/**/*"/>  
  125.             </fileset>  
  126.         </copy>  
  127.         <javac srcdir="${src.dir}" debug="true" destdir="${build.out}" >  
  128.             <classpath refid="compile.classpath" />  
  129.         </javac>  
  130.   
  131.         <copy todir="${build.out}">  
  132.             <fileset dir="${src.dir}">  
  133.                 <exclude name="**/*.java" />  
  134.                 <exclude name="resource/**/*"/>  
  135.                 <exclude name="images/**/*"/>  
  136.             </fileset>  
  137.         </copy>  
  138.     </target>  
  139.        
  140.     <target name="archive" depends="compile">  
  141.         <delete file="${dist.dir}/${dest.jar}" />  
  142.         <jar destfile="${dist.dir}/${dest.jar}"  
  143.             basedir="${build.dir}/classes" />  
  144.     </target>  
  145.        
  146.     <target name="build" depends="compile">  
  147.         <delete file="${dist.dir}/${dest.war}" />  
  148.         <war destfile="${dist.dir}/${dest.war}" webxml="${websrc.dir}/WEB-INF/web.xml">  
  149.             <classes dir="${build.dir}/classes"/>  
  150.             <webinf dir="${websrc.dir}/WEB-INF"/>  
  151.             <!--lib dir="${websrc.dir}/WEB-INF/lib"/-->  
  152.             <fileset dir="${websrc.dir}">  
  153.                 <patternset refid="build.pattern"/>  
  154.                 <exclude name="resource/**/*"/>  
  155.                 <exclude name="images/**/*"/>  
  156.             </fileset>         
  157.         </war>  
  158.         <!--copy file="${dist.dir}/${dest.war}" tofile="${dist.dir}/${date.current}.${time.current}_program_${dest.war}"/-->  
  159.     </target>  
  160.   
  161.     <target name="fullbuild" depends="compile">  
  162.         <delete file="${dist.dir}/${dest.war}" />  
  163.         <war destfile="${dist.dir}/${dest.war}" webxml="${websrc.dir}/WEB-INF/web.xml">  
  164.             <classes dir="${build.dir}/classes"/>  
  165.             <webinf dir="${websrc.dir}/WEB-INF"/>  
  166.             <!--lib dir="${websrc.dir}/WEB-INF/lib"/-->  
  167.             <fileset dir="${websrc.dir}">  
  168.                 <patternset refid="build.pattern"/>  
  169.             </fileset>         
  170.         </war>  
  171.         <copy file="${dist.dir}/${dest.war}" tofile="${dist.dir}/${date.current}.${time.current}_full_${dest.war}"/>  
  172.     </target>  
  173.   
  174.        
  175.     <target name="deploy" depends="unzip">  
  176.         <echo message="${deploy.dir}" />  
  177.         <delete dir="${build.dir}"/>  
  178.     </target>  
  179.   
  180.     <target name="zip" depends="deploycompile">  
  181.         <echo message="now stopping tomcat service"/>  
  182.         <exec executable="sc">  
  183.             <arg line="stop Tomcat5"/>  
  184.         </exec>  
  185.         <delete file="${dist.dir}/${dest.zip}" />  
  186.         <zip destfile="${deploy.dir}/${dest.zip}">  
  187.             <fileset dir="${build.dir}">  
  188.                 <include name="**/*"/>  
  189.                 <exclude name="resource/**/*"/>  
  190.                 <exclude name="images/**/*"/>  
  191.             </fileset>  
  192.         </zip>  
  193.     </target>  
  194.   
  195.     <target name="unzip" depends="zip">  
  196.         <sleep seconds="60"/>  
  197.         <unzip dest="${deploy.dir}/${deploy.web.dir}" overwrite="true" src="${deploy.dir}/${dest.zip}">  
  198.         </unzip>  
  199.         <echo message="now starting tomcat service"/>  
  200.         <exec executable="sc">  
  201.             <arg line="start Tomcat5"/>  
  202.         </exec>  
  203.     </target>      
  204.        
  205. </project>  
分享到:
评论
2 楼 java-admin 2008-01-30  
    
楼主 你厉害
1 楼 java-admin 2008-01-30  
这么好的东西,没有人顶,真是的!

相关推荐

    ANDROID_ANT自动编译打包签名教程

    因为项目的需要必须写一个ANDROID_ANT自动编译打包签名的脚本,终于奋斗了几天写完了,和大家分享一下

    通过ant脚本,编译打包android工程

    通过ant脚本,编译打包android工程。 编译打包android工程的ant脚本,Android官方提供的打包脚本。 有注释

    ant自动化发布脚本

    利用ant,自动化发布工程。具体过程包括:备份之前发布的工程,从svn checkout工程,编译工程,打包工程,关闭web服务器,删除已发布在web服务器的工程,复制打包的工程到web服务器,解压工程,启动web服务器。

    通过脚本,编译打包android工程

    通过ant脚本,编译打包android工程, 编译打包android工程的ant脚本。

    Powershell(脚本) Ant(编译)实现一键打包

    Powershell(脚本) Ant(编译)实现一键打包

    服务器 使用脚本打包编译java项目

    服务器 使用脚本打包编译java项目 包含了使用svn下载代码,ant编译打包,发布 等所有的过程

    android编译与ant打包

    在Java 中应用是平台无关性的,当然不会用平台相关的make脚本来完成这些批处理任务了,ANT本身就是这样一个流程脚本引擎,用于自动化调用程序完成项目的编译,打包,测试等。本文介绍了android编译和ant打包原理

    自定义NetBeans中的ant脚本

    自定义NetBeans工具生成的ant脚本,从此自己通过ant脚本让Netbeans清理、编译和打包。

    使用Ant构建web项目 从编译到测试 生成测试报告 打包 邮件发送 远程下载tomcat 部署运行一条龙服务之ant脚本

    使用Ant构建web项目 从编译到测试 生成测试报告 打包 邮件发送 远程下载tomcat 部署运行一条龙服务之ant脚本

    ant xml 打包

    ant对工程打包 ${basedir}\src"/&gt; ${env.JBOSS_HOME}"/&gt; ${basedir}\build"/&gt;

    通过Ant发布Android到手机的例子

    通过Ant发布Android到手机的例子,包含了编译,打包成APK文件,安装等ant脚本

    ant-android:蚂蚁脚本,编译,打包apk

    ant-androidAnt脚本,自动打包apk注意:1.env系统变量property environment="env"这里的env是你的系统环境变量,如果是linux系统,键入命令env,检查一下有没有下面这两个变量env.ANDROID_SDK_HOME env.JAVA_HOME前一...

    Android笔记之:App自动化之使用Ant编译项目多渠道打包的使用详解

    随着工程越来越复杂,项目越来越多,以及平台的迁移(我最近就迁了2回),还有各大市场的发布,自动化编译android项目的需求越来越强烈,后面如果考虑做持续集成的话,会更加强烈。 经过不断的尝试,在ubuntu环境下,...

    apache-ant-1.9.3-src.tar

    在Java 中应用是平台无关性的,当然不会用平台相关的make脚本来完成这些批处理任务了,ANT本身就是这样一个流程脚本引擎,用于自动化调用程序完成项目的编译,打包,测试等。除了基于JAVA是平台无关的外,脚本的格式...

    jocky 混肴编译rar包(ant和插件俩个版本)

    在应用的开发过程中,我们往往都会有一个Ant脚本,通过该脚本,能够对应用进行编译、打包、发布等一系列过程。因此,Jocky的最佳切入点便是对Ant的支持。 在Ant中使用Jocky非常简单: 1. 将lib\jocky-ant.jar ...

    Ant帮助文档

    当一个代码项目大了以后,每次重新编译,打包,测试等都会变得非常复杂而且重复,ANT本身就是这样一个流程脚本引擎,用于自动化调用程序完成项目的编译,打包,测试等。

    ant学习配套电子书教程

    4、速度快,向编译和打包这样的java常规工作都可以在ant的jvm中进行,节省了启动其他jvm所耗费的时间. 5、集成junit,适合进行xp开发模式所提倡的单元测试. 6、易于使用java进行功能扩展. 7、支持j2ee部署. 8、善于...

    android批量打包生成apk

    当你要将多个应用发布到多个推广渠道的时候,你会针对每一个渠道为android应用添加相应的渠道号,这样工作量会很大。这时你会想:如果有某种...用编译脚本build.xml,2.java调用ant,3.bat批处理文件(也是调用ant)

    Ant 1.9.2 API (CHM格式)

    主要可以帮助程序员进行java项目的的管理,包括批量编译、部署、文档生成等工作,其用途远不止如此,ant内置了大量的API进行各种文件系统操作,在各种应用服务器中都被广泛应用于程序和资源的部署。 Ant功能强大的...

    利用Ant和Eclipse有效地提高部署工作效率

    本文内容包括:工作场景用Eclipse3.1来创建Ant脚本Ant中使用property(属性)文件使用Ant任务从CVS中检出(checkout)源代码,并编译打包编译过程与产生不同目标环境的脚本分开执行解开WAR包利用Ant提供的filter任务...

Global site tag (gtag.js) - Google Analytics