java - 无法构建 NetBeans/Ant 项目

标签 java netbeans ant build

我继承了一个项目,最初是用NetBeans写的,用Ant搭建的。我是一名 Eclipse 用户并且使用过 Ant,但并不完全理解 NetBeans 使用 Ant 的特定方式。我知道它使用 build-impl.xml 文件(导入到 build.xml 中),但我不知道该文件是如何生成的/由 IDE 更新

我对几个类做了一些小改动,想构建一个 jar。我尝试从 build.xmlbuild-impl.xml 在 Eclipse 中运行 "clean""jar" 目标 但出现以下错误:

BUILD FAILED
C:\Devel\Projects\MyProject\nbproject\build-impl.xml:661: The following error occurred while executing this line:
C:\Devel\Projects\MyProject\nbproject\build-impl.xml:337: Compile failed; see the compiler error output for details.

第 661 行是此目标中的 j2seproject3 元素:

<target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
    <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
    <copy todir="${build.classes.dir}">
        <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
    </copy>
</target>

第 337 行是来自此目标的 javac 行:

<target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal">
    <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
        <attribute default="${src.dir}" name="srcdir"/>
        <attribute default="${build.classes.dir}" name="destdir"/>
        <attribute default="${javac.classpath}" name="classpath"/>
        <attribute default="${javac.processorpath}" name="processorpath"/>
        <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
        <attribute default="${includes}" name="includes"/>
        <attribute default="${excludes}" name="excludes"/>
        <attribute default="${javac.debug}" name="debug"/>
        <attribute default="${empty.dir}" name="sourcepath"/>
        <attribute default="${empty.dir}" name="gensrcdir"/>
        <element name="customize" optional="true"/>
        <sequential>
            <property location="${build.dir}/empty" name="empty.dir"/>
            <mkdir dir="${empty.dir}"/>
            <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
                <src>
                    <dirset dir="@{gensrcdir}" erroronmissingdir="false">
                        <include name="*"/>
                    </dirset>
                </src>
                <classpath>
                    <path path="@{classpath}"/>
                </classpath>
                <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
                <compilerarg line="${javac.compilerargs}"/>
                <customize/>
            </javac>
        </sequential>
    </macrodef>
</target>

我不知道这两个目标是关于什么的,也不知道它们失败的原因。我下载了 NetBeans7,希望在那里构建它会成功,但遇到了同样的错误。

我可以安全地从我的构建中删除这些目标吗?我需要更新 project.properties 文件吗?

感谢任何有助于构建它的帮助。

最佳答案

还有其他错误吗?之后出现了什么信息?是一堆 Java 编译错误,还是 <javac>任务本身没有执行?

<macrodef>正在定义一个名为 <javac> 的新宏将执行而不是原来的 <javac> . “等一下!”,你是说,不是已经有 <javac> 了吗?任务?

是的,这看起来像是在重新定义它。我通常认为这是一件坏事——特别是因为它不采用与 <javac> 相同的参数.为什么不叫它<netbeansc>还是什么?

@符号有点像属性。它们是您传递给宏的参数。

您有以下内容:

<j2seproject3:javac
    gensrcdir="${build.generated.sources.dir}"/>

这调用了几乎运行 ORIGINAL <javac> 的宏做编译的任务。我会确保定义了下面显示的所有属性。

<javac
    debug="${javac.debug}"
    deprecation="${javac.deprecation}"
    destdir="${build.classes.dir}"
    encoding="${source.encoding}"
    excludes="${excludes}"
    executable="${platform.javac}"
    fork="yes"
    includeantruntime="false"
    includes="${includes}"
    source="${javac.source}"
    sourcepath="${empty.dir}"
    srcdir="${srcdir}"
    target="${javac.target}"
    tempdir="${java.io.tmpdir}">
    <src>
       <dirset dir="${empty.dir}"
            erroronmissingdir="false">
            <include name="*"/>
       </dirset>
   </src>
   <classpath>
       <path path="${javac.classpath"/>
   </classpath>
   <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
   <compilerarg line="${javac.compilerargs}"/>
   <customize/>

关于java - 无法构建 NetBeans/Ant 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5995365/

相关文章:

java - 如何使用JSP限制网页中显示的数据库记录?

java - 如何在 Maven 插件上配置 File[]?

java - JNLP 错误,显示的代码与我的 JNLP 中的不同

java - 同一 NetBeans 项目中的 Clojure 和 Java 源代码

java - 如何在netbeans中打印1到10并打印奇数和偶数?

java - 在 Eclipse 中测试应用程序时读取为 JAR 准备的 XML 文件

java - 如何从 gradle 正确执行 ant.java?

java - 显示具有多个航点的两点之间的路线 Android Here Map Lite Edition

java - 使用JERSEY和JACKSON解析未知结构的POST请求

ant - 在 Intellij Idea 中为 Web 应用程序执行 Ant