【问题标题】:Ant build fails with no visible errorsAnt 构建失败,没有可见的错误
【发布时间】:2010-08-03 23:51:58
【问题描述】:

编辑:我最终在 Eclipse 中设置了整个项目,并且能够构建它。我不知道为什么会出现这个问题,希望我永远不必找到。

我的构建报告“BUILD FAILED”但没有报告任何错误时遇到问题。

我正在构建一个包含大量旧代码的大型应用程序,现在我很高兴能够修改这些代码。大多数其他开发人员已经使用 Eclipse 建立了他们的构建,但我正在尝试通过现有的 build.xml 文件构建它。

在设置完我的类路径后,构建运行顺利,但在开始编译步骤后不久,它返回:

Lots of "[javac] file.java" lines.

BUILD FAILED
<project path>/build.xml:201: Compile failed; see the compiler error output for details.

这没什么用。 build.log 除了堆栈跟踪之外没有其他信息:

at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1085)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:885)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

将-debug 标志添加到ant 会创建大量信息,并且由于类路径如此长(如此多的jar),很难对其进行排序。

这是ant中的目标:

  <target name="compile" depends="achmetadata">
    <mkdir dir="${path.build.classes}"/>
    <javac
      listfiles="yes"
      destdir="${path.build.classes}"
      classpathref="project.classpath"
      debug="on"
      deprecation="on"
      fork="yes"
      nowarn="no"
      memoryMaximumSize="512M"
      srcdir="${path.src.java}"
      source="1.4"
      target="1.4"
      >
    -><src path="${path.build.src}"/>
      <patternset refid="production-code"/>
    </javac>
  </target>

classpath 是通过 classpathref 设置的,并且通过 和 tags 包含了很多 jars。

对我应该寻找什么有什么想法吗?什么会导致蚂蚁这样失败?

【问题讨论】:

  • 堆栈跟踪的内容远不止这些。发布整个事情。
  • 其实,这就是蚂蚁给我的全部。它看起来对我来说是正确的。它的底部有 main 方法,顶部有 Javac.compile。
  • ${path.build.src} 的值是多少?您可以在 元素之前添加一个 元素,这将在编译时转储该值。能否也提供模式集的定义?

标签: java ant javac


【解决方案1】:

CLASSPATH 应该在 build.xml 中设置。如果您依赖于 CLASSPATH 环境变量,那么您就犯了一个错误。

看看这个 build.xml 是否工作得更好。研究目录结构并让您的目录结构与 build.xml 中的说明相匹配:

<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">

    <property name="version" value="1.6"/>
    <property name="haltonfailure" value="no"/>

    <property name="out" value="out"/>

    <property name="production.src" value="src"/>
    <property name="production.lib" value="lib"/>
    <property name="production.resources" value="config"/>
    <property name="production.classes" value="${out}/production/${ant.project.name}"/>

    <property name="test.src" value="test"/>
    <property name="test.lib" value="lib"/>
    <property name="test.resources" value="config"/>
    <property name="test.classes" value="${out}/test/${ant.project.name}"/>

    <property name="exploded" value="out/exploded/${ant.project.name}"/>
    <property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
    <property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>

    <path id="production.class.path">
        <pathelement location="${production.classes}"/>
        <pathelement location="${production.resources}"/>
        <fileset dir="${production.lib}">
            <include name="**/*.jar"/>
            <exclude name="**/junit*.jar"/>
            <exclude name="**/*test*.jar"/>
        </fileset>
    </path>

    <path id="test.class.path">                            
        <path refid="production.class.path"/>
        <pathelement location="${test.classes}"/>
        <pathelement location="${test.resources}"/>
        <fileset dir="${test.lib}">
            <include name="**/junit*.jar"/>
            <include name="**/*test*.jar"/>
        </fileset>
    </path>

    <path id="testng.class.path">
        <fileset dir="${test.lib}">
            <include name="**/testng*.jar"/>
        </fileset>
    </path>

    <available file="${out}" property="outputExists"/>

    <target name="clean" description="remove all generated artifacts" if="outputExists">
        <delete dir="${out}" includeEmptyDirs="true"/>
        <delete dir="${reports.out}" includeEmptyDirs="true"/>
    </target>

    <target name="create" description="create the output directories" unless="outputExists">
        <mkdir dir="${production.classes}"/>
        <mkdir dir="${test.classes}"/>
        <mkdir dir="${reports.out}"/>
        <mkdir dir="${junit.out}"/>
        <mkdir dir="${testng.out}"/>
        <mkdir dir="${exploded.classes}"/>
        <mkdir dir="${exploded.lib}"/>
    </target>

    <target name="compile" description="compile all .java source files" depends="create">
        <!-- Debug output
                <property name="production.class.path" refid="production.class.path"/>
                <echo message="${production.class.path}"/>
        -->
        <javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
            <classpath refid="production.class.path"/>
            <include name="**/*.java"/>
            <exclude name="**/*Test.java"/>
        </javac>
        <javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
            <classpath refid="test.class.path"/>
            <include name="**/*Test.java"/>
        </javac>
    </target>

</project>

【讨论】:

  • 我在 build.xml 中使用路径,而不是写出 CLASSPATH。我的意思是运行带有调试的 ant 会打印出传递给 javac 的 CLASSPATH,其中包含大约 50 个 jars(大项目)。我还从我的 build.xml 添加了目标。
  • 试试我的 build.xml 看看效果是否更好。
  • 我尝试了一个更简单的 build.xml。剥离除 javac 之外的所有内容(并且有很多目标和步骤可以完整构建该项目),但不幸的是,没有运气。我最终在 Eclipse 中设置了整个项目,这似乎很成功。
  • 我给你的build.xml你试过了吗?
  • 这个答案差不多 两年了。你真的特地来这里挑我不让你满意吗?您是否真的花费了您的小代表并驳斥了您认为不可接受的其他答案?
【解决方案2】:

您可以在调试模式下运行您的 ant 构建,以便您可以单步执行吗?在 build.xml 中设置断点。然后右键单击 build.xml 并选择 Debug As -> Ant Build(假设您使用的是 Eclipse)。这可能会帮助您弄清楚您的问题。

HTH。

【讨论】:

  • 当时我没有使用 Eclipse。调试标志没有多大帮助。我确实最终在 eclipse 中设置了整个项目,并且 eclipse 能够成功构建它。
  • 好的,如果您可以使用 eclipse 构建它,那么您应该确保 build.xml 中的路径与 eclipse 在项目属性(项目的 .classpath 文件)中设置的路径相同.
猜你喜欢
  • 2018-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-28
  • 2019-03-04
  • 2016-05-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多