【问题标题】:Java ant build failed because class not foundJava ant 构建失败,因为找不到类
【发布时间】:2016-01-14 07:08:05
【问题描述】:

我正在学习 Java ant。我在 Eclipse 中创建了一个项目,调用 hello world。然后我对项目进行了导出并创建了一个 ant 构建文件。当我运行 ant 文件失败时抱怨:BUILD FAILED C:\Users**\workspace\HelloWorld\build.xml:31:找不到类:javac1.8

并指向这一行:

<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">

我正在使用 Eclipse 开普勒。

这是我的 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="HelloWorld">
    <property environment="env"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.2"/>
    <property name="source" value="1.3"/>
    <path id="HelloWorld.classpath">
        <pathelement location="bin"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <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="HelloWorld.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
    <target name="HelloWorld">
        <java classname="HelloWorld" failonerror="true" fork="yes">
            <classpath refid="HelloWorld.classpath"/>
        </java>
    </target>
</project>

有人知道为什么会这样吗?

【问题讨论】:

    标签: java eclipse ant build.xml


    【解决方案1】:

    您的 Ant 版本是否低于 1.9.0? 如果是这样,它与 java 8 不兼容。 您最好更新当前版本的 Ant。

    如果您没有使用任何 java 8 语法,而只想使用它进行编译,您可以将“-Dbuild.compiler=javac1.7”传递给 javac

    【讨论】:

    • 我如何更新我的 ant 版本,因为它似乎指向 eclipse 插件文件夹
    • 这里的答案完美地解释了它:stackoverflow.com/questions/5206431/…
    • 嘿,我按照你的要求做了,我在这一行仍然遇到同样的错误:&lt;javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}"&gt;
    猜你喜欢
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    • 2015-12-08
    • 1970-01-01
    • 2013-06-21
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多