2013-07-10 40 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吗?其中一部分是惯性,其中一部分是遗留问题,最后是对新事物的简单的旧恐惧:-) –