我们使用Netbeans生成我们的Ant构建文件,并进行了一些小的调整。这使我们能够在Netbeans内部构建项目,并在命令行上运行ant以构建我们的项目,后者对于诸如完全重建或Jenkins持续构建和测试等事情非常有用。
我们根据需要自定义我们的build.xml文件,在Netbeans 8.2及之前的版本中很好地工作,但是在Netbeans pre-9(包括201708280001版的Dev版本)中,Netbeans开始在命令行上运行时破坏我们的构建。
我们会得到以下错误:
当在Netbeans中构建时,它可以正常工作。
如果我手动查看所有的build-impl.xml文件,我可以删除modulepath引用并使构建在命令行和Netbeans上正常工作,但最终Netbeans会重新引入modulepath设置。因此,这不是一个令人满意的长期解决方案。
我尝试升级到最新版本的Ant(1.9.9)和Netbeans Dev,但没有效果。我假设Netbeans使用的某个库在我的标准Ant 1.9.9中不存在,但我不知道是什么。
有人找到了一种解决方案,允许Ant从命令行正确构建Netbeans项目吗?
更新1:
使用Ant 1.10.1尝试,结果相同。
更新2:
在Java 9下运行命令行Ant未解决问题。
更新3:
将我的测试隔离到一个项目(orcb)中,并确保它在Java9下运行。仍然失败:
请注意有关源1.6的警告,这是Java9中的新警告。这是因为我们需要构建代码,以便在旧的JVM下运行(我们不能成功地强制客户升级)。
build.sh的内容如下:
注意: 平台参考用于确保我们正确地构建与旧版本的Java相对应的应用程序。
向Netbeans提交了一个工单: https://netbeans.org/bugzilla/show_bug.cgi?id=271487 更新4:
新工单: https://issues.apache.org/jira/browse/NETBEANS-1106 更新5:
这也影响到 Netbeans 11,如果您使用 Java 1.8 或更早版本,则无法在 Netbeans 中正确构建。
我们根据需要自定义我们的build.xml文件,在Netbeans 8.2及之前的版本中很好地工作,但是在Netbeans pre-9(包括201708280001版的Dev版本)中,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文件,我可以删除modulepath引用并使构建在命令行和Netbeans上正常工作,但最终Netbeans会重新引入modulepath设置。因此,这不是一个令人满意的长期解决方案。
我尝试升级到最新版本的Ant(1.9.9)和Netbeans Dev,但没有效果。我假设Netbeans使用的某个库在我的标准Ant 1.9.9中不存在,但我不知道是什么。
有人找到了一种解决方案,允许Ant从命令行正确构建Netbeans项目吗?
更新1:
使用Ant 1.10.1尝试,结果相同。
更新2:
在Java 9下运行命令行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-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:
这也影响到 Netbeans 11,如果您使用 Java 1.8 或更早版本,则无法在 Netbeans 中正确构建。
java -version
,查询您的Java版本,并告知出现错误时的版本信息。另外,请问NetBeans使用的Java版本是多少? - Naman