ant

跨平臺的xml腳本引擎,用於自動化調用程序完成項目的編譯,大包,測試,通常命名爲build.cml,能夠設置一些列target。css

target通常包括:html

* 任務1:usage 打印本 腳本的幫助信息(缺省)
* 任務2:clean <-- init 清空初始化環境
* 任務3:javadoc <-- build <-- init 生成JAVADOC
* 任務4:jar <-- build <-- init 生成JAR
* 任務5:all <-- jar + javadoc <-- build <-- init 完成以上全部任務:jar javadoc
 
ant標籤包括一下部分。
ant打包的步驟通常是:
1 創建一個臨時路徑,臨時存放須要打包得文件,下面有兩個文件夾,一個存放class文件,一個存放項目中的web文件
2 clean上一次打包得文件
3 編譯class文件到臨時路徑下class目錄中
4 將項目中web下的靜態文件 js,css,html,image等copy到臨時路徑下的web目錄中。
5 將項目中web下的配置文件copy到臨時路徑下的web目錄中。
6 將臨時路徑下的文件和項目文件中的lib文件打成war包
7 將war包放到服務器下面。
 
<project name="項目名" default="默認的運行目標" basedir="" description="項目的描述">
    <property file="build.properties" />
    <property name="xxxxJarPath" value="${tempPath}/xxxx.jar" />
    <property name="xxxxBuildPath" value="${tempPath}/xxxxBuildPath" />
    <property name="xxxxClassPath" value="${xxxxBuildPath}/classes" />
    <property name="xxxLibPath" value="${ProjectPath}/web/WEB-INF/lib" />
    <property name="webPath" value="${ProjectPath}/web" />
    <property name="webDest" value="${tempPath}/xxxx-web" />
     <property name="webDestZip" value="${tempPath}/xxxx-web/xxx.zip" />

    <target name="clean">
    <delete dir="${xxxxBuildPath}" />
    </target>

    <!--depends爲依賴的target,執行target前會執行depends target -->
    <target name="build" depends="clean">

        <!--建立class path-->
    <mkdir dir="${xxxxClassPath}" />

        <!--編譯class文件-->
    <javac destdir="${xxxxClassPath}" encoding="UTF-8"><!--class輸出路徑-->
        <src path="${xxxxSrcPath}" /><!--原文件路徑-->
        <classpath refid="xxxLibPath" /><!--支持的lib文件的路徑-->
     </javac>    
    </target>
    
    <!--建立jar -->
    <target name="create_xxxx_jar" depends="build">
    <jar destfile="${xxxxJarPath}" filesetmanifest="mergewithoutmain">
        <manifest>
            <attribute name="Main-Class" value="Utils.xxxxUtils" />
            <attribute name="Class-Path" value="." />
        </manifest>
        <fileset dir="${xxxxClassPath}" />
        <zipfileset excludes="META-INF/*.xx" src="${xxxLibPath}/poi-3[1].0.1-FINAL-.jar" />
    </jar>
    </target>

    <!--該標籤用來執行編譯生成的.class文件 -->
    <target name="run_xxxx" depends="create_xxxx_jar">
        <!--fork在一個新的虛擬機中運行該類 -->
        <java jar="${xxxxJarPath}" fork="true">
            <arg line="${webPath} ${webDest} ${xxxxResourse}" />
            <sysproperty key="file.encoding" value="utf-8" />
        </java>
    </target>

     <!--copy靜態文件,包括css,image,jsp/html -->
    <target name="copyStaticFile" depends="run_xxxx">
        <copy todir="${webDest}/css">    
            <fileset dir="${webPath}/css" />
        </copy>
        <copy todir="${webDest}/images">
            <fileset dir="${webPath}/images" />
        </copy>
        <copy todir="${webDest}/js">
            <fileset dir="${webPath}/js" />
        </copy>
        <copy todir="${webDest}">
            <fileset dir="${webDest}/html" />
        </copy>
        <delete dir="${webDest}/html" />
    </target>

    <!--將靜態文件打包-->
    <target name="staticFileZip" depends="copyStaticFile">
    <zip destfile="${webDestZip}">
        <fileset dir="${webDest}" />
    </zip>
    </target>

    <target name="MapperXMLCopy" depends="staticFileZip">
    <copy todir="${xxxxClassPath}">
        <fileset dir="${ProjectPath}/src" excludes="*.java,*/*.java,*/*/*.java,*/*/*/*.java,*/*/*/*/*.java,*/*/*/*/*/*.java,*/*/*/*/*/*/*.java,*/*/*/*/*/*/*/*.java" />
    </copy>
    </target>

    <!--copy 配置文件-->
    <target name="webCopy" depends="MapperXMLCopy">
    <copy todir="${webDest}/META-INF">
        <fileset dir="${ProjectPath}/web/META-INF"/>
    </copy>
    <copy todir="${webDest}/WEB-INF">
        <fileset file="${ProjectPath}/web/WEB-INF/*.xml"/>
    </copy>
    </target>

    <!--打成war包-->
    <target name="war" depends="webCopy">
    <war destfile="${tempPath}/xxxx.war" webxml="${MProjectPath}/web/WEB-INF/web.xml">
        <fileset dir="${webDest}"/>
        <lib dir="${xxxLibPath}"/>
        <classes dir="${xxxxClassPath}" />
    </war>
    </target>
    
    <!--將war包放到jboss或者tomcat目錄下-->
    <target name="moveWar" depends="war">
    <move todir="${xxxxWarDestPath}">
        <fileset file="${tempPath}/xxxx.war"/>
    </move>
    </target>
</project>            
相關文章
相關標籤/搜索