java 无法构建 NetBeans/Ant 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5995365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 13:52:53  来源:igfitidea点击:

Can't Build NetBeans/Ant Project

javanetbeansantbuild

提问by sdoca

I have inherited a project originally written in NetBeans using Ant to build. I am an Eclipse user and have used Ant but do not completely understand the NetBeans specific way of using Ant. I know it uses a build-impl.xmlfile (imported into the build.xml), but am at a loss as to how that file is generated/updatedby the IDE.

我继承了一个最初用 NetBeans 编写的项目,使用 Ant 进行构建。我是 Eclipse 用户并且使用过 Ant,但并不完全了解使用 Ant 的 NetBeans 特定方式。我知道它使用一个build-impl.xml文件(导入到build.xml),但我不知道generated/updatedIDE是如何处理该文件的。

I made some minor changes to a couple of classes and want to build a jar. I tried running the "clean"and "jar"targets in Eclipse from both the build.xmland build-impl.xmlbut get the following errors:

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

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.

Line 661 is the j2seproject3 element in this target:

第 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>

Line 337 is the javac line from this 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>

I have no idea what these two targets are about and why they're failing. I downloaded NetBeans7 hoping that building it there would succeed, but get the same errors.

我不知道这两个目标是什么以及它们为什么失败。我下载了 NetBeans7,希望在那里构建它会成功,但遇到相同的错误。

Can I safely remove these targets from my build? Do I need to update the project.properties file?

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

Any help getting this to build is appreciated.

任何帮助构建它的帮助表示赞赏。

采纳答案by David W.

Any other errors? What message appeared after that? Was it a bunch of Java compile errors, or did the <javac>task itself didn't execute?

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

The <macrodef>is defining a new macro named <javac>that will execute instead of the original <javac>. "Wait a second!", you're saying, isn't there already a <javac>task?

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

Yes there is, and this looks like it's redefining it. I would normally consider this a bad thing to do-- especially since it doesn't take the same arguments of <javac>. Why not call it <netbeansc>or something?

是的,这看起来像是在重新定义它。我通常会认为这是一件坏事——尤其是因为它不采用<javac>. 为什么不叫它<netbeansc>什么的?

The @signs are sort of like properties. They're parameters that you're passing to the macro.

这些@标志有点像属性。它们是您传递给宏的参数。

You have the following:

你有以下几点:

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

This calls the Macro that pretty much runs the ORIGINAL <javac>task to do the compile. I would make sure that all of the properties show below are defined.

这会调用几乎运行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/>

回答by Bento Gustavo De Sousa Pimente

corrected:

更正:

sorry about the past answer. solving some on the Gradle build on the line found that is advisable to create a new Relative layout. To sign it need to insert it into MainActivity.xml by replacing the old layout like

对过去的答案感到抱歉。解决了一些在Gradle build 上发现的问题,建议新建一个Relative 布局就行了。要签署它需要通过替换旧布局将其插入 MainActivity.xml

com.android.support: appcompat v7:28.0.0-alpha1';

com.android.support: appcompat v7:28.0.0-alpha1';

setContentView (R.layout.new_layout);

setContentView (R.layout.new_layout);

回答by Bento Gustavo De Sousa Pimente

I had the same issue about assigning different versions of the Java library on my computer, because I have different kinds of software on 3d modelling and visual design.

我在计算机上分配不同版本的 Java 库时遇到了同样的问题,因为我有不同类型的 3d 建模和视觉设计软件。

By affirming Java and administrator settings on Windows Control Panel, and resetting my computer, everything was ok.

通过确认 Windows 控制面板上的 Java 和管理员设置,并重置我的计算机,一切正常。