嗨我有一个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”添加到所有删除行
我不习惯蚂蚁而且我一直在尝试和尝试它并没有完全奏效。我希望我可以使用命令行,但不能。 奇怪的是大部分时间如果运行它2次它可以工作,但第一次真正奇怪的工作人员发生:要么不编译,要么重复的类。可能是什么原因?非常感谢
答案 0 :(得分:3)
你能解释一下它为什么会失败吗?快速浏览一下,我看到你的 compile-api 任务依赖于你的 lib.classpath 任务,但它不包含在 compile-api <中/ em>的依赖。这可能导致构建脚本有时工作而不是其他工作。
此外, lib.classpath 依赖于正在创建的 lib 目录,因此它也应该依赖于 -init-api 。
而且, 永远不会 依赖于 clean 。 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
_依赖于-init.api
。没有任何依赖于clean
。
答案 1 :(得分:0)
我认为如果目录不在那里就会抱怨,就像第一次运行它一样。您可能希望在删除任务中添加failonerror =“false”属性。
为了将来的参考,ant并没有真正用于构建Java - 大多数人已经转向了maven。