使用单个Ant构建脚本创建多个jar文件

时间:2012-06-24 18:39:42

标签: ant build.xml

我有一个要求,我需要从我工作区中存在的每个项目构建多个jar文件。你能告诉我如何编写一个build.xml来创建多个jar文件吗?我尝试过类似的代码并知道它的可能性,但是想知道需要遵循的最佳实践是什么。就我而言,我的工作区中有5个项目,我将不得不创建5个不同的罐子。还有外部依赖jar,需要包含在一些项目中以构建jar文件。下面是我编写的用于创建两个jar文件的示例代码。我为生成jar文件而编写的代码位于

之下
 <target name="compile" depends="compileVal, compileHib " description="compile the source for all">

</target>

<!-- ============================================= 
      target: compile the source for Valueobjects              
     ============================================= -->
<target name="compileVal" depends="clean" description="description">
    <echo message="Creating directory '${target}' if not present "></echo>
        <mkdir dir="${target}"/>
        <mkdir dir="${Classfiles}"/>
        <mkdir dir="${JarLocation}"/>
        <javac srcdir="../ValueObjects/src" destdir="${Classfiles}" />
</target>

    <!-- ================================= 
      target: compile              
     ================================= -->
    <target name="compileHib" depends="clean" description="description">
    <echo message="Creating directory '${target}' if not present "></echo>
        <mkdir dir="${target}"/>
        <mkdir dir="${Classfiles}"/>
        <mkdir dir="${JarLocation}"/>
        <javac srcdir="src" destdir="${Classfiles}" >
            <classpath>
                <pathelement location="${libloc}/hibernate3.jar"/>
                <pathelement location="${libloc}/hsqldb.jar"/>
                <pathelement location="${libloc}/jta.jar"/>
                <pathelement location="${libloc}/ojdbc5.jar"/>
                <pathelement location="${libloc}/commons-logging-1.1.1.jar"/>
                <pathelement location="${libloc}/postgresql-9.1-902.jdbc4.jar"/>
            </classpath>
        </javac>
     </target>

<!-- ================================= 
      target: name              
     ================================= -->
    <target name="copy-non-java-files" depends="" description="description">
        <copy todir="${Classfiles}" includeemptydirs="false">
                <fileset dir="src" excludes="**/*.java" />
        </copy>
    </target>

    <!-- ================================= 
      target: compress              
     ================================= -->
    <target name="build_jar" depends="buildValobj, buildHib" description="description">

    </target>

    <!-- ================================= 
      target: buildValobject jar             
     ================================= -->
<target name="buildValobj" depends="compileVal" description="creates the valueObject jar">
    <echo message="Creating the jar to Folder '${JarDest}'"> </echo>
        <jar destfile="${JarDest}/${RetValObName}" basedir="${Classfiles}" />
</target>

<!-- ================================= 
      target: buildHibjar               
     ================================= -->
<target name="buildHib" depends="compileHib, copy-non-java-files" description="description">
    <echo message="Creating the jar to Folder '${JarDest}'"> </echo>
        <jar destfile="${JarDest}/${RetHibName}" basedir="${Classfiles}" />
</target>



    <!-- ================================= 
      target: clean              
     ================================= -->

    <target name="clean">
        <echo message="Cleaning '${target}' folder"></echo>
        <delete includeemptydirs="true">
            <fileset dir="${target}" includes="**/*"/>
        </delete>
    </target>

在上面的代码中,我面临的问题是在尝试compileHib时虽然我已经指定了depends =“clean”。清洁不会发生。创建一个jar,其中包括已存在的文件以及已移动的新文件。不确定原因?虽然我已指定干净,但似乎没有发生干净的动作。能不能让我知道上面遗漏的内容。

请协助。提前谢谢

0 个答案:

没有答案