2013-07-10 126 views
0

您好我有螞蟻的build.xml問題,它的工作原理,但有時也不是第一次或在某些計算機等人的作品不Ant構建文件問題

所以在這裏,它是:

<project name="My-java-api" default="dist-api" basedir="."> 

<description> 
    Java API Buildfile 
</description> 

<property name="src" location="src"/> 
<property name="build" location="build"/> 
<property name="dist" location="dist"/> 
<property name="libs" location="libs"/> 

<!--if we don't remove folders, when we call compile-api 
and classes have already been built, it doesn't build again--> 

<target name="-init-api" depends="clean" 
     description="Create folders libs and build"> 
    <mkdir dir="${build}"/> 
    <mkdir dir="${libs}"/> 
    <mkdir dir="${dist}"/> 
</target> 

<!-- Here I call another buildfile of submodule located at the tree indicated I am 
sure the other buildfile works perfect --> 

<target name="-pre-build-api" depends="-init-api" 
     description="Create jelly jar and copy it to libs folder"> 
    <ant dir="../Libraries/jelly/core/" 
     antfile="build.xml" 
     target="standalone-jar"/> 
    <copy todir="${libs}"> 
     <fileset 
       dir="../Libraries/jelly/core/dist" 
       includes="jelly-standalone*.jar" /> 
    </copy> 
</target> 

<!--so now I create this classpath to use for making jar--> 

<path id="lib.classpath"> 
    <fileset dir="${libs}" includes="**/*.jar"/> 
</path> 

<!--I compile source code including the jar that I have just copied to libs--> 
<target name="compile-api" depends="-pre-build-api" > 
    <javac srcdir="${src}" 
      includeantruntime="false" 
      destdir="${build}" 
      classpathref="lib.classpath"> 
    </javac> 
</target> 
<!-- here i make jar with the classes and using the jar from external project, 
I want just one jar for everything --> 

<target name="dist-api" depends="compile-api" > 

    <jar jarfile="${dist}/name-java-api-0.1.jar" basedir="${build}" > 
     <zipgroupfileset dir="${libs}" includes="**/*.jar" /> 
    </jar> 
</target> 

<target name="clean" 
     description="clean up" > 
    <delete dir="${build}"/> 
    <delete dir="${dist}"/> 
    <delete dir="${libs}"/> 
</target> 

編輯:failonerror =「假」添加到全部刪除線

我不習慣螞蟻和我一直在努力,努力,它只是完全不是那麼回事。我希望我可以使用命令行,但不能。 奇怪的是,大多數情況下,如果運行它2次,它會工作,但第一次真奇怪的工作人員發生:要麼不編譯,要麼重複類。可能是什麼原因?非常感謝

+3

它失敗了什麼任務? – davidfmatheson

+1

您能否更具體地瞭解這些故障?你運行什麼任務?怎麼了? –

+0

我也不清楚你的意思是「課程是重複的」。 – davidfmatheson

回答

3

你能解釋它爲什麼會失敗嗎?快速瀏覽一下,我發現你的compile-api任務取決於你的lib.classpath任務,但它不包含在的編譯API的依賴中。這可能會導致構建腳本有時而不是其他人。

此外,lib.classpath取決於正在創建的LIB目錄,所以它也應當取決於-init-API

而且,你應該永遠有什麼取決於乾淨。 Ant構建是安裝的,所以他們不必執行不必要的步驟。例如,如果只更改一個源文件,則只有該源文件被重新編譯。你打破了構建腳本的每一次構建完成都強制清理的整個想法。


在你的build.xml看起來更近一點,我意識到還有一些其他問題。

這裏是一個build.xml與糾正的依賴關係。

<project name="My-java-api" default="dist-api" basedir="."> 

    <description> 
     Java API Buildfile 
    </description> 

    <property name="src" location="src"/> 
    <property name="build" location="build"/> 
    <property name="dist" location="dist"/> 
    <property name="libs" location="libs"/> 

    <!--if we don't remove folders, when we call compile-api --> 
    <!-- and classes have already been built, it doesn't build again--> 

    <target name="-init-api" 
     description="Create folders libs and build"> 
     <mkdir dir="${build}"/> 
     <mkdir dir="${libs}"/> 
     <mkdir dir="${dist}"/> 
    </target> 

    <!-- Here I call another buildfile of submodule located at the tree indicated I am --> 
    <!--sure the other buildfile works perfect --> 

    <target name="-pre-build-api" depends="-init-api" 
     description="Create jelly jar and copy it to libs folder"> 
     <ant dir="../Libraries/jelly/core/" 
      antfile="build.xml" 
      target="standalone-jar"/> 
     <copy todir="${libs}"> 
      <fileset 
       dir="../Libraries/jelly/core/dist" 
       includes="jelly-standalone*.jar" /> 
     </copy> 
    </target> 

    <!--so now I create this classpath to use for making jar--> 

    <target name="lib.classpath" 
     depends="-pre-build-api"> 
     <path id="lib.classpath" 
      depends="-pre-build-api"> 
      <fileset dir="${libs}" includes="**/*.jar"/> 
     </path> 
    </target> 

    <!--I compile source code including the jar that I have just copied to libs--> 
    <target name="compile-api" 
     depends="lib.classpath" > 
     <javac srcdir="${src}" 
      includeantruntime="false" 
      destdir="${build}" 
      classpathref="lib.classpath"> 
     </javac> 
    </target> 
    <!-- here i make jar with the classes and using the jar from external project, 
    I want just one jar for everything --> 

    <target name="dist-api" 
     depends="compile-api" > 

     <jar jarfile="${dist}/name-java-api-0.1.jar" basedir="${build}" > 
      <zipgroupfileset dir="${libs}" includes="**/*.jar" /> 
     </jar> 
    </target> 

    <target name="clean" 
     description="clean up" > 
     <delete dir="${build}"/> 
     <delete dir="${dist}"/> 
     <delete dir="${libs}"/> 
    </target> 
</project> 

注意dist-api取決於compile-api取決於lib.classpath取決於pre-build-api這_DEPENDS在-init.api。沒有任何東西依賴於clean

+0

感謝您的幫助David W唯一的問題是我得到錯誤:build.xml:33:路徑不支持「depends」屬性 – vallllll

+0

如果我刪除了「depends」屬性,那麼jar文件中的其中一個類是重複的,然後我沒有得到生成錯誤,但是當我在另一個項目中起訴這個文件時,它失敗 – vallllll

+0

@vallllll - 哎呀,這不是目標!這個''將在所有目標之前執行,並且如果'lib'目錄不存在所需的jar文件,則這將失敗。我們需要把它放到'compile-api'目標中,或者把它作爲'compile-api'所依賴的目標。 –

0

我認爲如果目錄不存在,它會發出抱怨,第一次運行時就會出現這種情況。您可能需要爲刪除任務添加failonerror =「false」屬性。

爲了將來的參考,螞蟻並沒有真正用於構建Java - 大多數人已經轉向了maven。

+0

謝謝我補充說我把這個添加到了所有我的刪除腳本,但仍然沒有解決整個問題。 – vallllll

+0

並非所有人都去過Maven。我們使用Ant。 –

+0

我支持ANT和Maven構建。你相信80%的Java構建(當然在企業中)仍然使用ANT嗎?其中一部分是慣性,其中一部分是遺留問題,最後是對新事物的簡單的舊恐懼:-) –