JDK9 EA Support
NOTE Always use latest JDK9 EA build when working with NetBeans Daily development builds. Refer to What does not Work chapter for latest updates on compatibility issues.
NetBeans IDE Daily Development builds contains also early (under development) support for JDK 9 EA development builds namely the new modular system for Java. (Download http://bits.netbeans.org/download/trunk/nightly/latest/)
Features are not complete, at this stage, and WILL break in the future. JDK 9 EA is the moving targets, which have not reached Feature Complete status yet.
The work started for Java SE support and projects (NB Ant project). Other areas like Java EE or Maven are not being worked on for JDK9 EA at this time. Later when Java SE support will be in desired state NetBeans developers of all other modules should start to use this for their work on making other NB modules to support JDK 9 EA and module system.
Sources and builds are available on AS IS basis (daily development builds) without any warranty and testing. Bugs could be filled for JDK 9 EA support into bugzilla with Keyword JDK_9.
Features and UI is still being designed and will change. Don't use these builds for real work! A lot of exceptions ...
NetBeans JDK9 support development is ongoing effort till NetBeans 9 reaches its Feature Freeze mileston.
- The NetBeans JDK 9 build runs on top of Java SE 8, you can download the latest update of Java SE 8 here. JDK 7 and older is not supported by NetBeans after NetBeans 8.1 release.
- Download the latest JDK 9 Early Access from https://jdk9.java.net/download/ page
- Download NB Daily Development build from http://bits.netbeans.org/download/trunk/nightly/latest/ or build it from sources.
- In some operating systems NetBeans, by default, launches on the most current JDK version available. Installing JDK 9 EA might cause the NB 9 daily development build, as well as other versions of Netbeans, to run with JDK 9. Although it is is possible to run the NB JDK 9 branch on JDK 9 (see below for instructions), you should consider configuring NetBeans (every version installed) to launch with JDK 8 (see Changing NetBeans JDK runtime platform below for instructions)
- Register the latest JDK 9 EA build as a Java Platform in NetBeans JDK9 build by means of Tools | Java Platforms | Add Platform.
NetBeans JDK 9 builds support:
- NB Java SE project support one JDK9/Jigsaw module - Single module project.
- Java SE Multi module project - Ant based project containing several modules and compiling them at once.
- Maven projects
- module-info.java support: editing works and using its statement to set module boundaries for projects
- All Editing features work according to what is declared in module-info.java
- Using other NB Java SE Single module projects as libraries (project dependency) is possible
- Compilation works
- Run & Debug projects work
- Unit tests can be compiled and run.
- All other features unrelated to Java language like SCM should work.
What DOES NOT work
When running NetBeans IDE daily Dev build on top of JDK9 EA build 150 or newer you might experience issues when some APIs are not accessible, this is due to strong encapsulation of APIs in non exported packages invoked through setAccessible() - this no longer works in b150 and newer. Similar exception will be printed to terminal or log file:
java.lang.reflect.InaccessibleObjectException: Unable to make field transient some_package.some_class.some_field accessible: module java.xyz does not "opens abc.xyz" to unnamed module @2a5ca609 at ....
Particular class/field/module might vary. NetBeans IDE JavaSE and JS distributions were fixed since daily build 201701130001 (Jan 13th) and now opens several packages for reflection. It might happen than when running daily dev build on top of JDK9 EA with additional modules/clusters installed then setAccessible to some other field might be used. It might be also invoked from bundled 3rd party library we even cannot fix. In such a case add a statement like this, e.g. -J--add-opens java.base/java.util=ALL-UNNAMED (provide your module and package) to netbeans.conf netbeans_default_options= and run IDE again. For modules in standard netbeans distros (Java EE,...) report the bug to NB Bugzilla using JDK_9 keyword. We will fix that in netbeans.conf in upcoming daily build.
How to start
This chapter uses NetBeans Java SE project type, based on Apache Ant.
Add JDK9 EA as a Java Platform
After adding JDK 9 EA as Java Platform to NetBeans create Jave SE project using New Project wizard. Setup the project to JDK9 in project Properties:
- In Libraries customizer set Java Platform to your JDK 9 EA Java platform.
- In Sources customizer set Source /Binary Format to JDK 9
Then add module-info.java. It is available under New File templates in category Java.
When adding module-info.java to existing application with some libraries on CLASSPATH then last step of New Java Module Info wizard lists these libraries.
It is possible to decide whether libs should stay on CLASSPATH or to be moved to MODULEPATH. See State of the module system paper, section Compatibility and Migration on how jar files without module-info are treated by JDK9
java.base module is by default added to any JDK9 app. You can now edit module-info.java with requires,...
Dependencies on Java Platform modules e.g. java.scripting is done in module-info.java file.
Project can have also dependency on another JDK 9 EA modular (module-info.java) NB project. Use Project Properties | Libraries customizer to add another project either into modulepath or classpath. Use Add Project... button.
This customizer was redesigned from previous NetBeans versions to adapt to coexistence of modulepath and classpath in JDK 9.
NetBeans currently supports JUnit tests which are part of same module as tested sources. If interested how modulepath, classpath, addExport, addmods, addReads are handled to run Junit tests then read this thread: JUnitTask + JDK9 question
The structure is very similar to non-modular Java development. Simply add JUnit tests into Test Packages or leverage existing JUnit tests in a project. Junit jar file needs to be added to Test Libraries. Then run the tests using project context menu 'Test Alt+F6 or Test File (Ctrl+F6) for single Java file.
JUnit tests in own module
NetBeans also support inside Java SE single module project to place tests inside own module. This is the only case when two module_info.java files can be used in this type of project. This way tests are more like black box as they are not a part of source module, thus module boundaries and package readability among modules play a role.
Start by adding module_info.java into Test Packages. Rename the module to something meaningful and different from source files, e.g. testModule Then add JUnit tests into some package. Resulting structure should look like following screen shot:
module_info.java looks like following:
NetBeans perform compilation and test execution which could replicated using these two command lines (just for illustration) using Ant junit task:
- Compile: javac -mp build/classes:junit.jar -XaddExports:srcModule/pkg=testModule -XaddReads:testModule=junit -d build/test/classes test/module-info.java test/pkg/test/AppTest.java
- Run Tests: java -mp build/test/classes:build/classes:junit.jar -addmods srcModule,testModule -XaddExports:srcModule/pkg=testModule,testModule/pkg.test=junit -XaddReads:testModule=junit -cp hamcrest-core.jar -m junit/org.junit.runner.JUnitCore pkg.test.AppTest
With release of Apache Maven Compiler Pluging v 3.6.0 it is possible to develop Maven projects in NetBeans 9 for JDK9. Simply open or create Maven project in NetBeans IDE. Set appropriate JDK 9 EA as Project Java Platform and change Source/Binary Format to 9.
If module_info.java is present in Maven project then all Java libraries used in a project became JDK9 modules - are placed to MODULEPATH by Maven Compiler Plugin.
It is also possible to add declared dependencies to module_info.java via a context action on the dependency node.
NetBeans Maven support is under development to provide other productivity features for Maven projects.
- Unit tests are not working, waiting for Maven Surefire plugin to support JDK9.
- has to support modulepath
- failures and warnings in jar(error), javadoc(warning), aggregate(error)
- needs to detect new version scheme
- and maybe some other plugins depending on maven-archiver
Module Dependency Graph
The Graph View of the module-info.java file provides module dependency graph.
Running NetBeans on JDK9 EA as run time Java platform
It is possible to try this NetBeans build to run on JDK9 EA build as NetBeans IDE runtime platform. Use it with care as JDK9 EA is still under development as well as NetBeans JDK9 branch. We adopt NetBeans JDK9 to JDK9 EA changes but in some cases it takes some time.
Necessary command line options are in nb_install_dir/etc/netbeans.conf file. If you discover you need to -add-export another JDK module then add it in this file and file a bug for NB JDK9.