简体   繁体   中英

Netbeans Dev (9.x) Java Projects will not build outside of Netbeans

We use Netbeans to generate our Ant build files with some small adjustments. This allows us to build our projects inside Netbeans and to run ant on the command line to build our projects outside of Netbeans. The latter is useful for things such a complete rebuild or Jenkins continuous build and test.

We do customize our build.xml files as needed and this has work well for us with Netbeans 8.2 and prior versions, but with Netbeans pre-9 (Dev versions including 201708280001), Netbeans has started to break our builds when run on the command line.

We get the following error:

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

When building inside Netbeans, it works correctly.

If I go through all the build-impl.xml files by hand, I can remove the modulepath references and the build works correctly on both the command line and Netbeans, but eventually Netbeans will reintroduce the modulepath settings. So, this is not a satisfactory long term solution.

I've tried upgrading to the latest version of Ant (1.9.9) and Netbeans Dev, but it had no effect. I'm assuming there is some library that Netbeans brings with its version of Ant that is not present in my stock Ant 1.9.9, but I have no idea what it is.

Has anyone found a solution that allows Ant to build Netbeans projects correctly from the command line?

Update 1

Tried with Ant 1.10.1 with the same results.

Update 2

Running the command line Ant under Java 9 did not resolve the problem.

Update 3

Isolated my test to just one project (orcb) and made sure it ran under Java9. Still fails:

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

Note the warnings about source 1.6, which is a new warning in Java9. This is a result of needing to build our code so it can run under older JVMs (we cannot successfully push our customers to upgrade).

build.sh reads as followings:

$ 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

Note: the platform references are used to make sure we build correctly against older version of Java.

Opened a ticket with Netbeans: https://netbeans.org/bugzilla/show_bug.cgi?id=271487

Update 4

New ticket: https://issues.apache.org/jira/browse/NETBEANS-1106

Update 5

This affects Netbeans 11 as well and will not even build correctly within Netbeans if you are using Java 1.8 or earlier.

As pointed out in the comments section, this type of errors comes up when you try and execute your based project with java version released prior to the Java-9 release build.

So you can change the version of Java installed on your machine by updating the JAVA_HOME to include the path to Java9's jdk.

Traverse the directory of your project, confirm using java -version and you would be using java version "9". Once confirmed, you can execute your project as well and it should be resolved.

Tracked the problem down to a problem in one of our own build scripts. To work around a different Netbeans problem we defined our own macro:

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

In there, for Java 1.8 we didn't handle the modulepath attribute, which we added:

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

This seems to have cleared up our problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM