孔浩 ant-学习笔记 20150325

****************************************************************
08--bulid.xml
<?xml version="1.0" encoding="UTF-8"?>
<project default= "execute">
      
       <fileset id= "src.path" dir= "src" >
             <include name= "**/*.*"/>
             <!--<exclude name="**/*.java"/>-->
       </fileset>
      
       <target name= "init">
             <delete dir= "build"></delete>
             <mkdir dir= "build"/>
             <mkdir dir= "build/src"/>
             <mkdir dir= "build/classes"/>
             <mkdir dir= "build/dist"/>
       </target>
      
       <target name= "copySrc" depends= "init">
             <copy todir= "build/src">
                   <fileset refid= "src.path"></fileset>
             </copy>
       </target>
      
       <target name= "compile" depends= "init">
             <javac destdir= "build/classes" srcdir= "src"></javac>
       </target>
      
       <target name= "jar" depends= "compile">
             <jar destfile= "build/dist/hello.jar" basedir="build/classes">
                   <manifest>
                         <attribute name= "Main-Class" value="ant.zttc.edu.cn.HelloWorld"/>
                         <attribute name= "Build-By" value= "Konghao"/>
                   </manifest>
             </jar>
       </target>
      
       <target name= "execute" depends= "jar,copySrc">
            
             <echo>基于类路径的classname来完成执行 </echo>
             <java classname= "ant.zttc.edu.cn.HelloWorld" classpath="build/classes">
                   <arg value= "张三"/>
                   <arg value= "李四"/>
                   <arg value= "王五"/>
             </java>
            
             <echo>基于jar文件执行</echo>
             <java jar= "build/dist/hello.jar" fork= "true">
                   <arg value= "张三"/>
                   <arg value= "李四"/>
                   <arg value= "王五"/>
             </java>
            
       </target>
</project>
****************************************************************
09--bulid2.xml
<?xml version="1.0" encoding="UTF-8"?>
<project default= "execute">
      
       <property file= "build.properties"></property>
      
       <property name= "build.dir" location= "binary"></property>
       <!--使用属性定义相应的路径时,一定要使用location而不要使用value-->
       <property name= "build.classes" location="${build.dir}/classes"></property>
       <property name= "build.src" location= "${build.dir}/src"></property>
       <property name= "build.lib.dir" location="${build.dir}/dist"></property>
       <property name= "execute.classes" value="ant.zttc.edu.cn.HelloWorld"></property>
       <property name= "jar.name" value= "hello.jar"></property>
      
       <!-- 把环境变量中的参数放到env变量中-->
       <property environment= "env"></property>
      
       <target name= "test">
             <echo>${ant.home}</echo>
             <echo>${ant.version}</echo>
             <echo>${env.CLASSPATH}</echo>
             <echo>${env.OS}</echo>
       </target>
      
       <fileset id= "src.path" dir= "src" >
             <include name= "**/*.*"/>
             <!--<exclude name="**/*.java"/>-->
       </fileset>
      
       <target name= "init">
             <delete dir= "${build.dir}"></delete>
             <mkdir dir= "${build.dir}"/>
             <mkdir dir= "${build.src}"/>
             <mkdir dir= "${build.classes}"/>
             <mkdir dir= "${build.lib.dir}"/>
       </target>
      
       <target name= "copySrc" depends= "init">
             <copy todir= "${build.src}">
                   <fileset refid= "src.path"></fileset>
             </copy>
       </target>
      
       <target name= "compile" depends= "init">
             <javac destdir= "${build.classes}" srcdir= "src"></javac>
       </target>
      
       <target name= "jar" depends= "compile">
             <jar destfile= "${build.lib.dir}/${jar.name}" basedir="${build.classes}">
                   <manifest>
                         <attribute name= "Main-Class" value="ant.zttc.edu.cn.HelloWorld"/>
                         <attribute name= "Build-By" value= "Konghao"/>
                   </manifest>
             </jar>
       </target>
      
       <target name= "execute" depends= "jar,copySrc">
            
             <echo>基于类路径的classname来完成执行 </echo>
             <java classname= "${execute.classes}" classpath="${build.classes}">
                   <arg value= "张三"/>
                   <arg value= "李四"/>
                   <arg value= "王五"/>
             </java>
            
             <echo>基于jar文件执行</echo>
             <java jar= "${build.lib.dir}/${jar.name}" fork= "true">
                   <arg value= "张三"/>
                   <arg value= "李四"/>
                   <arg value= "王五"/>
             </java>
            
       </target>
</project>
****************************************************************
12--build3.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
      
      
       <property name= "src.dir" location= "src"></property>
       <property name= "test.src.dir" location= "test"></property>
       <property name= "lib.dir" location= "lib"></property>
       <property name= "build.dir" location= "build"></property>
       <property name= "build.classes" location="${build.dir}/classes"></property>
       <property name= "build.test.dir" location="${build.dir}/test"></property>
       <property name= "build.test.classes" location="${build.test.dir}/classes"></property>
       <property name= "build.test.report" location="${build.test.dir}/report"></property>
      
       <property name= "run.test.class" value= "**/Test*.class"></property>
      
       <path id= "compile-path">
             <fileset dir= "${lib.dir}" includes= "*.jar"></fileset>
       </path>
      
       <path id= "compile-test-path">
             <path refid= "compile-path"></path>
             <pathelement location= "${build.classes}"/>
       </path>
      
       <path id= "run-test-path">
             <path refid= "compile-test-path"></path>
             <pathelement location= "${build.test.classes}"/>
       </path>
      
       <target name= "clean">
             <echo>进行项目的清理工作</echo>
             <delete dir= "${build.dir}"></delete>
       </target>
       <target name= "init">
             <echo>进行项目的初始化</echo>
             <delete dir= "${build.dir}"></delete>
             <mkdir dir= "${build.classes}"/>
             <mkdir dir= "${build.test.dir}"/>
             <mkdir dir= "${build.test.classes}"/>
             <mkdir dir= "${build.test.report}"/>
       </target>
      
       <target name= "compile" depends= "init">
             <echo>编译源文件</echo>
             <javac failonerror= "true" includeantruntime= "true" destdir="${build.classes}" srcdir="${src.dir}" classpathref="compile-path"></javac>
       </target>
      
       <target name= "compile-test" depends= "compile">
             <echo>编译测试文件</echo>
             <javac failonerror= "true" includeantruntime= "true" srcdir="${test.src.dir}" destdir="${build.test.classes}" classpathref="compile-test-path"></javac>
       </target>
      
       <target name= "run-test" depends= "compile-test">
             <echo>运行单元测试</echo>
             <junit printsummary= "false" haltonerror= "false">
                   <classpath refid= "run-test-path"></classpath>
                   <formatter type= "brief" usefile= "false"/>
                   <!--<test name="${run.test.class}"></test> -->
                   <formatter type= "xml"/>
                   <batchtest todir= "${build.test.report}">
                         <fileset dir= "${build.test.classes}" includes="${run.test.class}"></fileset>
                   </batchtest>
             </junit>
             <junitreport todir= "${build.test.report}">
                   <fileset dir= "${build.test.report}" includes="TEST-*.xml"></fileset>
                   <report format= "frames" todir="${build.test.report}/html"/>
             </junitreport>
       </target>
      
       <target name= "end" depends= "run-test">
             <echo>整个过程结束</echo>
       </target>
</project>
****************************************************************
14--build4.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
       <property name= "src.dir" location= "src"></property>
       <property name= "build.dir" location= "build"></property>
       <property name= "build.classes" location="${build.dir}/classes"></property>
       <property name= "build.doc" location="${build.dir}/doc/api"></property>
       <property name= "zip.dir" location= "${build.dir}/zip"></property>
       <property name= "version" value= "SNAPSHOT_0.1"></property>
       <property name= "project.name" value= "user_${version}"></property>
       <property name= "zip.name" value= "user_${version}.zip"></property>
      
       <target name= "clean">
             <echo>进行项目的清理工作</echo>
             <delete dir= "${build.dir}"></delete>
       </target>
       <target name= "init">
             <echo>进行项目的初始化</echo>
             <delete dir= "${build.dir}"></delete>
             <mkdir dir= "${build.classes}"/>
             <mkdir dir= "${build.doc}"/>
       </target>
       <target name= "doc" depends= "init">
             <javadoc sourcepath= "${src.dir}" private= "true" windowtitle="mydoc"
                         use="true"
                         packagenames="cn.edu.*" destdir="${build.doc}"
                         charset="UTF-8" docencoding="UTF-8" encoding="UTF-8">
                   <classpath path= "${build.classes}"></classpath>
             </javadoc>
       </target>
       <target name= "zip" depends= "doc">
             <zip destfile= "${zip.dir}/${zip.name}" duplicate= "preserve">
                   <zipfileset dir= "${build.doc}" includes= "**/*.*" prefix="${project.name}/doc/api"></zipfileset>
                   <zipfileset dir= "${src.dir}" includes= "**/*.*" prefix="${project.name}/src"></zipfileset>
             </zip>
       </target>
       <target name= "ftp" depends= "zip">
             <ftp server= "localhost" userid= "kh" password= "123" action="put" remotedir="user">
                   <fileset dir= "${zip.dir}" includes= "*.zip"></fileset>
             </ftp>
       </target>
</project>
****************************************************************
转存失败重新上传取消
转存失败重新上传取消
****************************************************************
转存失败重新上传取消
****************************************************************
转存失败重新上传取消
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
rapid-framework配置文件
<!--
  All rights reserved.
  author: badqiu
{ $Id: build.xml,v 1.4 2007/05/15 07:48:36 baichao_qiu Exp $ }
-->
<!-- ======================================================================= -->
<!-- build file -->
<!-- ======================================================================= -->
<project name= "rapid-framework" basedir= "." default= "war">
       <tstamp></tstamp>
      
       <property environment= "env"/>
       <property file= "build.properties" />
      
       <!--版本控制信息-->
       <property name= "version" value= "v1.0.3"></property>
       <property name= "version.message" value= "version:${version} build:${cctimestamp}"/>
       <property name= "version.file" value= "version.txt"></property>
       <target name= "generate_version">
             <echo file= "${dir.src.web}/${version.file}" append= "no" message="${version.message}"/>
       </target>
      
       <!-- 主要路径修改START -->
       <path id= "lib.classpath">
             <fileset dir= "${dir.src.web}/WEB-INF/lib" >
                   <include name= "**/*.jar"/>
             </fileset>
             <fileset dir= "${tomcat.home}">
                   <include name= "lib/*.jar"/>
                   <include name= "common/lib/*.jar"/>
             </fileset>
       </path>
      
       <path id= "dirs.java.src">
             <pathelement path= "java_src"/>
       </path>
       <path id= "dirs.test.src">
             <pathelement path= "java_test"/>
       </path>
                  
       <!-- 主要路径修改END -->
            
       <target name= "prepare">
             <echo message= "tomcat.home=${tomcat.home}" />
             <echo message= "version.message=${version.message}" />
             <mkdir dir= "${dir.dist}"/>
             <mkdir dir= "${dir.dist.java}"/>
             <mkdir dir= "${dir.dist.test}"/>
             <mkdir dir= "${dir.dist}/${dir.src.web}" />
       </target>
      
       <target name= "clean">
             <delete dir= "${dir.dist}"></delete>
       </target>
                  
       <target name= "war" depends= "compile-src">
             <war destfile= "${dir.dist}/${context.path}.war" webxml="${dir.src.web}/WEB-INF/web.xml" >
                   <classes dir= "${dir.dist.java}" includes="**/*.*"></classes>
                   <fileset dir= "${dir.src.web}" includes= "**/*">
                         <exclude name= "WEB-INF/classes/**/*.*"/>
                   </fileset>
                   <fileset dir= "${dir.dist}/${dir.src.web}" includes="**/*" />
             </war>
       </target>
       <target name= "compile-src" depends= "prepare">
            
             <javac
                   nowarn="yes" target="${compile.version}" source="${compile.version}" encoding="${encoding}"
                   destdir="${dir.dist.java}" debug="true"
                   classpathref="lib.classpath">
                    <src refid= "dirs.java.src"/>
             </javac>
            
             <copy todir= "${dir.dist.java}">
                   <fileset dir= "java_src" excludes= "**/*.java"/>
             </copy>
            
       </target>
      
       <target name= "compile-test" depends= "compile-src">
            
             <javac destdir= "${dir.dist.test}"
                   includes="**/*.*"  target="${compile.version}"
                   source="${compile.version}" encoding="${encoding}">
                   <src refid= "dirs.test.src"/>
                   <classpath>
                         <path refid= "lib.classpath"/>
                         <path path= "${dir.dist.java}"/>
                   </classpath>
             </javac>
            
             <copy todir= "${dir.dist.test}">
                   <fileset dir= "java_test" excludes= "**/*.java"/>
             </copy>
       </target>
      
       <target name= "compile-all" description= "compile java src and java test source">
             <antcall target= "compile-src"/>
             <antcall target= "compile-test"/>
       </target>
            
       <target name= "jar" depends= "test">
             <jar jarfile= "${dir.dist}/${jar.name}">
                   <fileset dir= "${dir.dist.java}">
                         <include name= "META-INF/**"/>
                         <include name= "**"/>
                   </fileset>
             </jar>
       </target>
       <target name= "jar.source" depends= "">
             <jar jarfile="${dir.dist}/${ant.project.name}-${version}-source.jar">
                   <fileset dir= "java_src" >
                         <include name= "**/*.java"/>
                   </fileset>
             </jar>
       </target>
                              
       <!-- 运行前请将junit.jar加入ant runtime classpath
            打开Window>>Perferences>>Ant>>Runtime>>Classpath里加入junit.jar-->
       <target name= "test" depends= "compile-all">
             <delete dir= "${dir.test.report}" failonerror= "no"/>
             <mkdir dir= "${dir.test.report}"/>
             <junit printsummary= "yes" fork= "yes" haltonfailure= "yes" dir="${basedir}"  maxmemory="256M">
                  
                   <classpath>
                         <path refid= "lib.classpath"/>
                         <pathelement path= "${dir.dist.java}"/>
                         <pathelement path= "${dir.dist.test}"/>
                   </classpath>
                        
                   <formatter type= "plain"/>
                   <formatter type= "xml"/>
                   <formatter type= "brief"/>
                  
                   <batchtest todir= "${dir.test.report}" haltonfailure="no">
                         <fileset dir= "${dir.dist.test}">
                               <include name= "**/*Test.class"/>
                         </fileset>
                   </batchtest>
             </junit>
            
             <antcall target= "test-report"></antcall>
       </target>
      
      
    <!-- - - - - - - - - - - - - - - - - -
          target: test-report                     
         - - - - - - - - - - - - - - - - - -->
    <target name="test-report">
             <junitreport todir= "${dir.test.report}">
                   <fileset dir= "${dir.test.report}">
                         <include name= "TEST-*.xml"/>
                   </fileset>
                   <report format= "frames" todir= "${dir.test.report}"/>
             </junitreport> 
    </target>
       <target name= "javadoc">
             <javadoc  destdir= "${dir.javadoc}" windowtitle="${ant.project.name}"
                   source="1.5" access="protected" author="true" version="true" use="true"
                   encoding="${encoding}"
                   header=''>
                   <sourcepath refid= "dirs.java.src"/>
                   <classpath refid= "lib.classpath"/>
                  
                  
                   <doctitle><![CDATA[<h1>${ant.project.name}</h1>]]></doctitle>
                   <bottom>API</bottom>
             </javadoc>
       </target>
       <target name= "zip" depends= "clean,prepare">
             <zip zipfile="${dir.dist}/${ant.project.name}-${version}.zip">
                   <zipfileset dir= "." prefix="${ant.project.name}-${version}">
                         <include name= "java_src/**"/>
                         <include name= "build.xml"/>
                         <include name= "build.properties"/>
                         <include name= "readme.txt"/>
                   </zipfileset>
             </zip>
       </target>
       <target name= "cc_main" description= "用于持续集成工具CruiseControl的接入" >
             <antcall target= "clean"></antcall>
             <antcall target= "test"></antcall>
             <antcall target= "war"></antcall>
       </target>
      
</project>
****************************************************************

 

posted @ 2020-02-29 12:17  my_flash  阅读(34)  评论(0)    收藏  举报