[英]Ant build file issue
嗨,我在使用ant 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" 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 =“ false”添加到所有刪除行
我不習慣螞蟻,而且我一直在嘗試,這並不起作用。 我希望我可以只使用命令行,但不能。 奇怪的是,大多數情況下,如果將其運行兩次就可以了,但是第一次真正奇怪的工作人員就發生了:要么不編譯,要么重復兩個類。 可能是什么原因? 非常感謝
您能解釋一下為什么它會失敗嗎? 快速瀏覽一下,我發現您的compile-api任務依賴於lib.classpath任務,但未包含在compile-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
, 而 lib.classpath
取決於 _depends -init.api
pre-build-api
。 沒有什么依賴clean
。
我認為這會抱怨目錄是否不存在,就像您第一次運行它的情況一樣。 您可能想將failonerror =“ false”屬性添加到刪除任務。
為了將來參考,ant在構建Java時不再使用太多了-大多數人都轉而使用maven。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.