gpt4 book ai didi

java - Ant构建文件问题

转载 作者:行者123 更新时间:2023-12-01 23:43:20 25 4
gpt4 key购买 nike

您好,我的 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"添加到所有删除行

我不习惯 ant,我一直在尝试,但它不太有效。我希望我可以只使用命令行,但不能。奇怪的是,大多数时候,如果运行它两次,它就可以工作,但第一次会发生真正奇怪的事情:要么无法编译,要么类被重复。可能是什么原因?非常感谢

最佳答案

你能解释一下为什么它可能会失败吗?快速浏览一下,我发现您的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

关于java - Ant构建文件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17575557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com