【问题标题】:Using ant and build.xml error使用 ant 和 build.xml 错误
【发布时间】:2014-05-21 23:38:53
【问题描述】:

当我尝试在 GL 服务器上运行我的程序时,出现错误。此外,我们有两个包,一个包含所有内容,另一个是包含 Driver.java 的驱动程序包。它运行程序。

构建失败 项目“AutoFill”中不存在目标“run”。

这是为什么?这是我的 build.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
          Any modifications will be overwritten.
          To include a user specific buildfile here, simply create one in the same
          directory with the processing instruction <?eclipse.ant.import?>
          as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="AutoFill">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="AutoFill.classpath">
    <pathelement location="bin"/>
</path>
<target name="init">
    <mkdir dir="bin"/>
    <copy includeemptydirs="false" todir="bin">
        <fileset dir="src">
            <exclude name="**/*.launch"/>
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
</target>
<target name="clean">
    <delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
    <echo message="${ant.project.name}: ${ant.file}"/>
    <javac debug="true" debuglevel="${debuglevel}" destdir="bin"
includeantruntime="false" source="${source}" target="${target}">   
        <src path="src"/>
        <classpath refid="AutoFill.classpath"/>
    </javac>
</target>
<target description="Build all projects which reference this project. Useful to 
includeantruntime="false" source="${source}" target="${target}">
<target description="copy Eclipse compiler jars to ant lib directory" name="init-
    <copy todir="${ant.library.dir}">
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </copy>
    <unzip dest="${ant.library.dir}">
        <patternset includes="jdtCompilerAdapter.jar"/>
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse 
 compiler">
    <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
    <antcall target="build"/>
</target>
<target name="MaxHeap">
    <java classname="proj3.MaxHeap" failonerror="true" fork="yes">
        <classpath refid="AutoFill.classpath"/>
    </java>
</target>
<target name="Driver">
    <java classname="driver.Driver" failonerror="true" fork="yes">
        <classpath refid="AutoFill.classpath"/>
    </java>
</target>
</project>

【问题讨论】:

  • 你的目标是什么,你的构建参数是什么?看起来 - 正如它所说 - 你没有“运行”目标。
  • 我不太确定。我的驱动程序类驱动整个程序,是这样吗?

标签: java xml eclipse ant


【解决方案1】:

我已在此处重新格式化您的 build.xml。它有一些问题:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="AutoFill">
    <property environment="env"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.7"/>
    <property name="source" value="1.7"/>
    <path id="AutoFill.classpath">
        <pathelement location="bin"/>
    </path>

    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.launch"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>

    <target name="clean">
        <delete dir="bin"/>
    </target>

    <target name="cleanall" depends="clean"/>

    <target name="build"
        depends="build-subprojects, build-project"/>

    <target name="build-subprojects"/>

    <target name="build-project"
        depends="init">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true"
            debuglevel="${debuglevel}"
            destdir="bin"
            includeantruntime="false"
            source="${source}"
            target="${target}">   
            <src path="src"/>
            <classpath refid="AutoFill.classpath"/>
        </javac>
    </target>

    <!-- Something happened here... -->
    <target
        description="Build all projects which reference this project. Useful to "/>
    <!-- includeantruntime="false" source="${source}" target="${target}"> -->

    <!-- Something happened to the name of this target -->
    <target name="init-"
        description="copy Eclipse compiler jars to ant lib directory">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins"
                includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins"
                includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>

    <!-- Something happened to this target name -->
    <target name="build-eclipse compiler"
        description="compile project with Eclipse compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target>

    <target name="MaxHeap">
        <java classname="proj3.MaxHeap"
            failonerror="true" fork="yes">
            <classpath refid="AutoFill.classpath"/>
        </java>
    </target>

    <target name="Driver">
        <java classname="driver.Driver"
            failonerror="true" fork="yes">
            <classpath refid="AutoFill.classpath"/>
        </java>
    </target>
</project>

我不知道你是不是抄错了,但它根本就不是现在的有效 Ant 构建文件。你可能想检查你的帖子,看看你是否遗漏了什么。

您的错误非常简单。您没有名为 run 的目标。我不知道你为什么要执行它。 (也许是在你的build.xml 部分搞砸了。

有效的目标是:

  • 初始化
  • 干净
  • 完全干净
  • 构建
  • 构建项目
  • 构建子项目
  • 初始化-??? (目标名称不完整)
  • build-eclipse 编译器(目标名称无效。不能包含空格)
  • MaxHeap(Java 可执行文件)
  • 驱动程序(Java 可执行文件)

如果您尝试编译此项目,您希望运行build-projectbuild 目标而不是run。 (build-projectbuild 都做同样的事情)。

如果您尝试运行某个程序,MaxHeapDriverbuild.xml 中仅有的两个 Java 可执行目标。

因此,您可能想要执行目标build,然后执行DriverMaxHeap

【讨论】:

  • 我让 Eclipse 为我构建了一个 build.xml。我认为这就是问题所在。
  • 我看到它是一个 Eclipse 构建的文件。我重新格式化了它,所以我可以阅读它。那时我发现您发布的内容存在几个问题。
  • 有没有办法让 Eclipse 为我构建一个正确的?
  • 我不知道。我是 CM 而不是开发人员。我知道 Eclipse 有自己的构建算法,因此它不需要 Ant 构建文件来构建和部署。我知道你可以通过Eclipse生成一个build.xml,但我们通常自己编写。
  • @user2161813 你在 Eclipse 中使用了什么来创建 build.xml?
猜你喜欢
  • 2013-10-24
  • 1970-01-01
  • 2013-04-05
  • 2015-01-15
  • 1970-01-01
  • 2012-07-31
  • 1970-01-01
  • 2016-11-14
  • 2015-01-16
相关资源
最近更新 更多