当前位置: 首页 > 知识库问答 >
问题:

Netbeans开发(9.x)Java项目不会在Netbeans之外构建

锺离阿苏
2023-03-14

我们使用Netbean生成我们的蚂蚁构建文件,并进行一些小调整。这允许我们在Netbean中构建项目,并在命令行上运行ant来构建Netbean之外的项目。后者对于诸如完全重建或Jenkins连续构建和测试之类的事情是有用的。

我们确实定制了我们的构建。xml文件,这在Netbeans 8.2和以前的版本中非常适用,但在Netbeans pre-9(开发版本包括201708280001)中,Netbeans在命令行上运行时开始破坏我们的构建。

我们得到以下错误:

BUILD FAILED
C:\Users\Stephen\hcs\orc.trunk\nb\build.xml:278: The following error occurred while executing this line:
C:\Users\Stephen\hcs\orc.trunk\nb\build.xml:229: The following error occurred while executing this line:
C:\Users\Stephen\hcs\orc.trunk\nb\ServerLibWOC\nbproject\build-impl.xml:1623: Unknown attribute [modulepath]

Total time: 2 minutes 35 seconds

在Netbeans内部构建时,它可以正常工作。

如果我手动浏览所有的build-impl.xml文件,我可以删除模块路径引用,并且构建在命令行和Netbean上都能正常工作,但是最终Netbean将重新引入模块路径设置。因此,这不是一个令人满意的长期解决方案。

我尝试升级到最新版本的Ant(1.9.9)和Netbeans Dev,但没有效果。我假设Netbeans的Ant版本附带了一些库,这些库在我的Ant1.9.9中并不存在,但我不知道它是什么。

有没有人找到一个解决方案,允许蚂蚁从命令行正确地构建网络豆项目?

更新1

用蚂蚁1.10.1尝试,结果相同。

更新2

在Java9下运行命令行Ant并没有解决这个问题。

更新3

将我的测试隔离到一个项目(orcb),并确保它在Java9下运行。仍然失败:

Stephen@Stephen-VPC ~/hcs/orc.trunk/nb/orcb
$ echo $JAVA_HOME
/cygdrive/c/jdk1.9.ea

Stephen@Stephen-VPC ~/hcs/orc.trunk/nb/orcb
$ java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

$ ./build.sh
Buildfile: C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build.xml

-pre-init:

-init-private:

-init-user:

-init-project:

-init-macrodef-property-impl:

-set-source-dir:

-init-macrodef-property:

-init-modules-supported:

-do-init:

-post-init:

-init-check:

-init-ap-cmdline-properties:

-init-macrodef-modulename:

-init-source-module-properties:

-init-macrodef-javac-with-module:

-init-which-javac-to-use:

-init-macrodef-javac-with-processors.java.1.8:

-init-macrodef-javac-with-processors.java.9:

-init-macrodef-javac-with-processors:

-init-macrodef-javac-without-processors.java.1.8:

-init-macrodef-javac-without-processors.java.9:

-init-macrodef-javac-without-processors:

-init-macrodef-javac:

-init-macrodef-test-impl:

-init-macrodef-junit-init:

-init-test-properties:

-init-macrodef-junit-prototype-with-module:

-init-macrodef-junit-prototype-without-module:

-init-macrodef-junit-single:

-init-macrodef-junit-batch:

-init-macrodef-junit:

-init-macrodef-junit-impl:
Trying to override old definition of task http://www.netbeans.org/ns/j2se-project/3:test-impl

-init-macrodef-testng:

-init-macrodef-testng-impl:

-init-macrodef-test:

-init-macrodef-junit-debug-impl:

-init-macrodef-test-debug-junit:

-init-macrodef-testng-debug:

-init-macrodef-testng-debug-impl:

-init-macrodef-test-debug-testng:

-init-macrodef-test-debug:

-init-debug-args:

-init-macrodef-nbjpda:

-init-macrodef-debug:

-init-macrodef-java-with-module:

-init-macrodef-java-with-unnamed-module:

-init-macrodef-java-without-module:

-init-macrodef-java:

-init-presetdef-jar:

-init-ap-cmdline-supported:

-init-ap-cmdline:

init:

-deps-clean-init:

deps-clean:

-do-clean:
   [delete] Deleting directory C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build

-post-clean:

clean:

-pre-init:

-init-private:

-init-user:

-init-project:

-init-macrodef-property-impl:

-set-source-dir:

-init-macrodef-property:

-init-modules-supported:

-do-init:

-post-init:

-init-check:

-init-ap-cmdline-properties:

-init-macrodef-modulename:

-init-source-module-properties:

-init-macrodef-javac-with-module:

-init-which-javac-to-use:

-init-macrodef-javac-with-processors.java.1.8:

-init-macrodef-javac-with-processors.java.9:

-init-macrodef-javac-with-processors:

-init-macrodef-javac-without-processors.java.1.8:

-init-macrodef-javac-without-processors.java.9:

-init-macrodef-javac-without-processors:

-init-macrodef-javac:

-init-macrodef-test-impl:
Trying to override old definition of task http://www.netbeans.org/ns/j2se-project/3:test-impl

-init-macrodef-junit-init:

-init-test-properties:

-init-macrodef-junit-prototype-with-module:

-init-macrodef-junit-prototype-without-module:

-init-macrodef-html" target="_blank">junit-single:

-init-macrodef-junit-batch:

-init-macrodef-junit:

-init-macrodef-junit-impl:
Trying to override old definition of task http://www.netbeans.org/ns/j2se-project/3:test-impl

-init-macrodef-testng:

-init-macrodef-testng-impl:

-init-macrodef-test:

-init-macrodef-junit-debug-impl:

-init-macrodef-test-debug-junit:

-init-macrodef-testng-debug:

-init-macrodef-testng-debug-impl:

-init-macrodef-test-debug-testng:

-init-macrodef-test-debug:

-init-debug-args:

-init-macrodef-nbjpda:

-init-macrodef-debug:

-init-macrodef-java-with-module:

-init-macrodef-java-with-unnamed-module:

-init-macrodef-java-without-module:

-init-macrodef-java:

-init-presetdef-jar:

-init-ap-cmdline-supported:

-init-ap-cmdline:

init:

-deps-jar-init:

deps-jar:

-check-automatic-build:

-clean-after-automatic-build:

-verify-automatic-build:

-pre-pre-compile:
    [mkdir] Created dir: C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes

-add-build-versions-status:
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes

-pre-compile:

-copy-persistence-xml:

-compile-depend:

-do-compile:
    [mkdir] Created dir: C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\empty
    [mkdir] Created dir: C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\generated-sources\ap-source-output
    [javac] Compiling 1058 source files to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
    [javac] warning: [options] source value 1.6 is obsolete and will be removed in a future release
    [javac] warning: [options] target value 1.6 is obsolete and will be removed in a future release
    [javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 3 warnings
     [copy] Copying 35 files to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes

-init-check-cobertura:

-instrument-coverage:

-post-compile:

compile:

-pre-jar:

-check-module-main-class:

-set-module-main-class:

-pre-pre-jar:
    [mkdir] Created dir: C:\Users\Stephen\hcs\orc.trunk\nb\orcb\dist

-do-jar-create-manifest:

-do-jar-copy-manifest:
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build

-do-jar-set-mainclass:

-do-jar-set-profile:

-do-jar-set-splashscreen:

-do-jar-jar:

-init-macrodef-copylibs:

-do-jar-copylibs:
 [copylibs] Copy libraries to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\dist\lib.
 [copylibs] Building jar: C:\Users\Stephen\hcs\orc.trunk\nb\orcb\dist\ORMC.jar
     [echo] To run this application from the command line without Ant, try:
     [echo] java -jar "C:\Users\Stephen\hcs\orc.trunk\nb\orcb\dist\ORMC.jar"

-do-jar-delete-manifest:

-do-jar-without-libraries:

-do-jar-with-libraries:

-post-jar:
    [mkdir] Created dir: C:\Users\Stephen\hcs\orc.trunk\nb\orcb\dist\signed
      [jar] Building jar: C:\Users\Stephen\hcs\orc.trunk\nb\orcb\dist\signed\ORMC.jar

-do-jar:

-pre-deploy:

-check-jlink:

-do-deploy:

-post-deploy:

deploy:

-check-filename-prop:

-set-jnlp-filename-custom:

-set-jnlp-filename-default:

-init-filename:

-test-jnlp-enabled:

-create-tmp-manifest:

-copy-tmp-manifest:
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build

-security-props-check:

-test-signjars-task-available:

-unavailable-signjars-task:

-check-signing-possible:

-set-mixed-code-properties:

-init-macrodef-extend-manifest:

-add-trusted-only-attribute:

-add-trusted-library-attribute:

-check-manifest-codebase:

-extend-manifest-codebase-copy:

-extend-manifest-codebase-web:

-extend-manifest-codebase-other:

-extend-manifest-codebase-override-warning:

-extend-manifest-codebase-override:

-check-manifest-permissions:

-extend-manifest-permissions-sandbox:

-extend-manifest-permissions-all:

-extend-manifest-permissions-override:

-extend-manifest-application-name:

-check-manifest-application-library-allowable-codebase:

-extend-manifest-application-library-allowable-codebase-copy:

-extend-manifest-application-library-allowable-codebase-web:

-extend-manifest-application-library-allowable-codebase-other:

-extend-manifest-application-library-allowable-codebase-override-warning:

-extend-manifest-application-library-allowable-codebase-override:

-check-manifest-caller-allowable-codebase:

-extend-manifest-caller-allowable-codebase-copy:

-extend-manifest-caller-allowable-codebase-web:

-extend-manifest-caller-allowable-codebase-other:

-extend-manifest-caller-allowable-codebase-override-warning:

-extend-manifest-caller-allowable-codebase-override:

-add-manifest-security:

-test-jnlp-type:

-do-jar-applet:

-do-jar-jnlp-application:

-do-jar-jnlp-component:

-do-jar-jnlp:

jnlp:

jar:

-pre-init:

-init-private:

-init-user:

-init-project:

-init-macrodef-property-impl:

-set-source-dir:

-init-macrodef-property:

-init-modules-supported:

-do-init:

-post-init:

-init-check:

-init-ap-cmdline-properties:

-init-macrodef-modulename:

-init-source-module-properties:

-init-macrodef-javac-with-module:

-init-which-javac-to-use:

-init-macrodef-javac-with-processors.java.1.8:

-init-macrodef-javac-with-processors.java.9:

-init-macrodef-javac-with-processors:

-init-macrodef-javac-without-processors.java.1.8:

-init-macrodef-javac-without-processors.java.9:

-init-macrodef-javac-without-processors:

-init-macrodef-javac:

-init-macrodef-test-impl:
Trying to override old definition of task http://www.netbeans.org/ns/j2se-project/3:test-impl

-init-macrodef-junit-init:

-init-test-properties:

-init-macrodef-junit-prototype-with-module:

-init-macrodef-junit-prototype-without-module:

-init-macrodef-junit-single:

-init-macrodef-junit-batch:

-init-macrodef-junit:

-init-macrodef-junit-impl:
Trying to override old definition of task http://www.netbeans.org/ns/j2se-project/3:test-impl

-init-macrodef-testng:

-init-macrodef-testng-impl:

-init-macrodef-test:

-init-macrodef-junit-debug-impl:

-init-macrodef-test-debug-junit:

-init-macrodef-testng-debug:

-init-macrodef-testng-debug-impl:

-init-macrodef-test-debug-testng:

-init-macrodef-test-debug:

-init-debug-args:

-init-macrodef-nbjpda:

-init-macrodef-debug:

-init-macrodef-java-with-module:

-init-macrodef-java-with-unnamed-module:

-init-macrodef-java-without-module:

-init-macrodef-java:

-init-presetdef-jar:

-init-ap-cmdline-supported:

-init-ap-cmdline:

init:

-deps-jar-init:

deps-jar:

-check-automatic-build:

-clean-after-automatic-build:

-verify-automatic-build:

-pre-pre-compile:

-add-build-versions-status:
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes
     [copy] Copying 1 file to C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\classes

-pre-compile:

-copy-persistence-xml:

-compile-depend:

-do-compile:

-init-check-cobertura:

-instrument-coverage:

-post-compile:

compile:

-pre-pre-compile-test:
    [mkdir] Created dir: C:\Users\Stephen\hcs\orc.trunk\nb\orcb\build\test\classes

-pre-compile-test:

-init-test-javac-module-properties-with-module:

-init-test-module-properties-without-module:

-init-test-module-properties:

-compile-test-depend:

-do-compile-test:

BUILD FAILED
C:\Users\Stephen\hcs\orc.trunk\nb\orcb\nbproject\build-impl.xml:1660: Unknown attribute [modulepath]

Total time: 25 seconds

请注意关于源1.6的警告,这是Java9中的新警告。这是因为需要构建我们的代码,以便它可以在旧的JVM下运行(我们无法成功地推动客户升级)。

build.sh内容如下:

$ cat build.sh
export JAVA_HOME=/cygdrive/c/jdk1.9.ea
"c:/Program Files (x86)/NetBeans Dev 201709180002/extide/ant/bin/ant" -Dplatforms.JDK32_1.6.home=c:/jdk1.6.0_43 -Dplatforms.JDK32_1.7.home=C:/jdk_1.7.0_79/ -Dlibs.CopyLibs.classpath=C:/Users/Stephen/hcs/orc.trunk/lib/netbeans/org-netbeans-modules-java-j2seproject-copylibstask.jar clean jar compile-test

注意:平台引用用于确保我们针对旧版本的Java正确构建。

已使用Netbeans打开票证:https://netbeans.org/bugzilla/show_bug.cgi?id=271487

更新4

新票:https://issues.apache.org/jira/browse/NETBEANS-1106

更新5

这也会影响Netbean 11,如果您使用Java1.8或更早版本,甚至无法在Netbean中正确构建。

共有2个答案

夏侯昊明
2023-03-14

正如评论部分所指出的,当您尝试使用java-9发布版本之前发布的java版本执行基于java-9的项目时,会出现这种类型的错误。

因此,您可以通过更新Java_HOME以包含Java9的jdk路径来更改机器上安装的Java版本。

遍历项目目录,使用java-version确认,您将使用java版本“9”。一旦确认,您也可以执行您的项目,它应该得到解决。

潘翊歌
2023-03-14

在我们自己的一个构建脚本中跟踪到问题。为了解决不同的Netbeans问题,我们定义了自己的宏:

<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">

在这里,对于Java 1.8,我们没有处理modulepath属性,我们添加了:

        <attribute default="${empty.dir}" name="modulepath"/>

这似乎解决了我们的问题。

 类似资料:
  • 根据JavaFX部署库,在活动JDK中找不到 我使用了JoséPereda Maven方法,它在NetBeans中运行得很好,但只要我尝试使用“java-jar-mavenproject1-1.0-SNAPSHOT-jar-with-dependencies.jar”在外部运行它,我就会得到以下错误:“错误:缺少JavaFX运行时组件,运行此应用程序需要这些组件” “md.mavenproject

  • 我是java语言的新手。我试着做我的第一个节目参考YouTube。但当我点击“运行”按钮时,它就不起作用了。我不知道为什么,但所有的构建或代码都是成功的。也许我有一些小错误…(?)有人能帮忙吗?在此输入图像说明

  • 我有一个maven应用程序,它从不清理,只直接构建或只使用依赖项构建。 org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1的POM无效,传递依赖项(如果有)将不可用,请启用调试日志以了解更多详细信息 --maven-clean-plugin:2.4.1:clean(default-clean)@model--- 总时间:0.870秒完成时间:

  • 我在Ubuntu12.10上运行NetBeans7.3。我正在学习一门Java Web开发课程,所以我有一个名为jsage8的项目,其中包含了我为该课程所做的工作。以前,这个项目在Projects选项卡中显示得很好,但现在打开这个项目什么也做不到。当我在打开项目菜单中单击打开它时,它只是说“没有项目打开”。然而,它将打开一个不是基于web的项目的普通Java项目文件夹。目前项目中只有一个index

  • 我正在将我们的构建从Ant转换为Gradle。我们的第一步是添加Gradle构建文件,这样我们就可以开始使用Gradle作为构建工具。这让我们可以使用现有的构建脚本使用Ant进行构建,并将其转换为随时间推移的渐变。我只想让Gradle调用现有的Ant构建文件。我们的项目都是NetBeans项目,都有build.xml和nbproject/build-implt.xml文件。有些项目需要NetBea

  • 问题内容: 我创建了一个NetBeans项目。我将项目文件夹压缩到另一台机器上,并尝试在NetBeans中打开它。NetBeans并未将其标识为NetBeans项目。我以前已经以这种方式转移了项目,但是为什么现在不起作用?我的项目文件是否已损坏。有什么办法可以从中检索我的文件吗? 问题答案: 尝试使用从现有资源创建新项目。这样可以解决问题。