利用ant編譯釋出打包jar檔案和打包api文件為rar檔案

iteye_17072發表於2011-04-15

首先在build.properties檔案中配置好釋出時的路徑及版本號、釋出名稱及釋出者等等。。然後執行build.xml檔案。

build.properties

#
#該檔案用於配置釋出和打包時所需配置
#

#釋出版本號
build.version=0.1

#釋出路徑
build.path=D:/target

#釋出名稱
build.name=test

#釋出title
build.title=smart rDelta API

#釋出者
build.created-by=Smart rDelta SDT

#vendor
build.vendor=Stone Age Co. Ltd.

#最終釋出名稱
final.name=${build.name}-${build.version}

#打包後API文件的名稱
doc.name=${build.name}-${build.version}-doc

 

 build.xml

<?xml version="1.0"?>
<project name="TestAnt" default="doc">

<!-- 定義properies -->
<property file="build.properties"/>
<property name="src.dir" value="src" />
<property name="classes.dir" value="classes" />
<property name="lib.dir" value="lib" />

<!-- 定義classpath -->
<path id="compile.classpath">
<fileset file="${lib.dir}/*.jar" />
<pathelement path="${classes.dir}" />
</path>

<!-- 初始化任務 -->
<target name="init">
<!-- 建立構建目錄 -->
<echo message="Running init ..."/>
</target>

<!-- 清除構建檔案和目錄 -->
    <target name="clean" description="Clean build and distribution directories">
    <echo message="Running clean ..."/>
        <delete dir="${build.path}"/>
    </target>

<!-- 編譯 -->
<target name="compile" depends="init" description="compile the source files">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" target="1.6">
<classpath refid="compile.classpath" />
</javac>
</target>

<!-- 打包成jar -->
<target name="pack" depends="compile" description="make .jar file">
<mkdir dir="${build.path}"/>
<jar destfile="${build.path}/${final.name}.jar" basedir="${classes.dir}">
<exclude name="**/*Test.*" />
<exclude name="**/Test*.*" />
<manifest>
<attribute name="Specification-Title" value="${build.title}" />
<attribute name="Created-By" value="${build.created-by}" />
<attribute name="Specification-Version" value="${build.version}" />
<attribute name="Specification-Vendor" value="${build.vendor}" />
</manifest>
</jar>
</target>

<!-- 輸出並打包api文件成rar -->
<target name="doc" depends="pack,compile" description="create api doc">
<echo message="Running API Doc ..."/>
        <tstamp>
            <format property="current.year" pattern="yyyy"/>
        </tstamp>
        <javadoc sourcepath="${src.dir}"
                 destdir="${build.path}/${doc.name}"
                 author="true"
                 version="true"
     use="true"
                 doctitle="&lt;h1&gt;${build.title} ${build.version}&lt;/h1&gt;"
                 windowtitle="${build.name} ${build.version}"
                 bottom="Copyright &amp;copy; 1998-${current.year} - ${build.vendor}">
            <classpath refid="compile.classpath"/>
        </javadoc>
<!-- 打包API檔案和目錄 -->
<echo message="Compressing API Doc ..."/>
        <zip destfile="${build.path}/${doc.name}.rar">
            <zipfileset dir="${build.path}/${doc.name}"   prefix="${doc.name}"/>
        </zip>
<!-- 打包之後清除構建的API檔案和目錄以及classes目錄 -->
<echo message="Deleting classes ..."/>
<delete dir="${classes.dir}"/>
<echo message="Deleting API Doc ..."/>
<delete dir="${build.path}/${doc.name}"/>
</target>

</project>
 

相關文章