JDK9Support

(Difference between revisions)
m
 
(40 intermediate revisions not shown)
Line 1: Line 1:
-
<h1>JDK9 EA Support</H1>
+
NetBeans has been donated by Oracle to Apache, where it continues to be actively developed. Go to [https://netbeans.apache.org netbeans.apache.org] for the latest details, go to [https://netbeans.apache.org/download/nb90/ https://netbeans.apache.org/download/nb90] in particular.
-
NetBeans IDE previews early experimental support for [https://jdk9.java.net/download/ JDK 9 EA development builds] including project Jigsaw, the new modular system for Java.
+
<!--
-
The NetBeans team is providing this as a preview of development work done in NetBeans IDE with the goal to have comprehensive support of JDK9 with modules (Jigsaw project) at the time of release of JDK 9. Features are not complete, at this stage, and WILL break in the future. JDK 9 and the Jigsaw project are also moving targets, which have not reach Feature Complete status yet.
+
 
 +
<h1>Oracle NetBeans</h1>
 +
 
 +
<h3>JDK9 EA Support</h3>
 +
'''NOTE''' Always use latest JDK9 EA build when working with NetBeans Daily development builds. Refer to [[#not_working|What does not Work chapter]] for latest updates on compatibility issues.
 +
 
 +
NetBeans IDE [http://bits.netbeans.org/download/trunk/nightly/latest/ Daily Development builds] contains also early (under development) support for [https://jdk9.java.net/download/ 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.
+
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 without any warranty. [https://netbeans.org/bugzilla/enter_bug.cgi Bugs could be filled] for JDK 9 EA support into bugzilla with Keyword '''JDK_9'''.  
+
Sources and builds are available on '''AS IS''' basis (daily development builds) without any warranty and testing. [https://netbeans.org/bugzilla/enter_bug.cgi 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 ...
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 done in '''jet-main''' repository on a branch '''jdk9'''. Daily builds are available at http://bits.netbeans.org/netbeans/nb9-for-jdk9_jigsaw/daily/latest/ this is Java SE distro only.
+
NetBeans JDK9 support development is ongoing effort till NetBeans 9 reaches its Feature Freeze mileston.  
-
 
+
-
Regular NetBeans Development builds (planned NetBeans 8.2 release) does not fully support JDK 9 and module system.
+
==Getting Started==
==Getting Started==
# The NetBeans JDK 9 build runs on top of Java SE 8, you can download the latest update of [http://www.oracle.com/technetwork/java/javase/downloads/index.html Java SE 8 here]. JDK 7 and older is not supported by NetBeans after NetBeans 8.1 release.
# The NetBeans JDK 9 build runs on top of Java SE 8, you can download the latest update of [http://www.oracle.com/technetwork/java/javase/downloads/index.html 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, build 111 or newer.
+
# Download the latest JDK 9 Early Access from https://jdk9.java.net/download/ page  
-
# Download NB JDK 9 dev build from http://bits.netbeans.org/netbeans/nb9-for-jdk9_jigsaw/daily/latest/ or build it from sources.
+
# '''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 JDK 9 branch 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 ([[#jdk9_runtime|see below]] for instructions), you should consider configuring NetBeans (every version installed) to launch with JDK 8 (see [[#nb_faq|Changing NetBeans JDK runtime platform]] below for instructions)
+
## 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 ([[#jdk9_runtime|see below]] for instructions), you should consider configuring NetBeans (every version installed) to launch with JDK 8 (see [[#nb_faq|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''.  
+
# Register the latest JDK 9 EA build as a ''Java Platform'' in NetBeans JDK9 build by means of ''Tools | Java Platforms | Add Platform''.
 +
 
==What works==
==What works==
-
NetBeans JDK 9 builds supports:  
+
NetBeans JDK 9 builds support:  
* NB Java SE project support one JDK9/Jigsaw module - Single module project.  
* 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
* 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
* All Editing features work according to what is declared in module-info.java
Line 30: Line 39:
* Compilation works
* Compilation works
* Run & Debug projects work  
* Run & Debug projects work  
-
* Unit tests can be compiled and run. NetBeans supports two way how to JUnit your modular project.
+
* Unit tests can be compiled and run.
* All other features unrelated to Java language like SCM should work.
* All other features unrelated to Java language like SCM should work.
 +
<span id="not_working"></span>
==What DOES NOT work==
==What DOES NOT work==
-
* Prevents execution and debugging of JDK9 projects:  https://netbeans.org/bugzilla/show_bug.cgi?id=262602
+
===Strong Encapsulation===
-
* Multiple JDK9 modules in one NB project
+
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 [http://mail.openjdk.java.net/pipermail/jdk9-dev/2016-November/005276.html 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:
-
* Maven projects don't work
+
<pre>
 +
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 ....
 +
</pre>
 +
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 ==
== How to start ==
-
Add JDK9 EA as a Java Platform
+
This chapter uses NetBeans Java SE project type, based on Apache Ant.
 +
 
 +
=== Add JDK9 EA as a Java Platform ===
[[image: Jigsaw_J_Platform.png]]
[[image: Jigsaw_J_Platform.png]]
Line 46: Line 63:
# In Libraries customizer set '''Java Platform''' to your JDK 9 EA Java platform.
# In Libraries customizer set '''Java Platform''' to your JDK 9 EA Java platform.
# In Sources customizer set '''Source /Binary Format''' to '''JDK 9'''
# In Sources customizer set '''Source /Binary Format''' to '''JDK 9'''
 +
 +
=== Add module-info.java ===
Then add module-info.java. It is available under New File templates in category Java.
Then add module-info.java. It is available under New File templates in category Java.
[[image: Jigsaw_New_m-i.j.png]]
[[image: Jigsaw_New_m-i.j.png]]
 +
 +
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.
 +
 +
[[image: AddModuleInfo.png]]
 +
 +
It is possible to decide whether libs should stay on CLASSPATH or to be moved to MODULEPATH. See [http://openjdk.java.net/projects/jigsaw/spec/sotms/#compatibility--migration  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 Jigsaw app. You can now edit module-info.java with requires,...
+
java.base module is by default added to any JDK9 app. You can now edit module-info.java with requires,...
 +
 
 +
=== Project dependencies ===
 +
Dependencies on Java Platform modules e.g. java.scripting is done in module-info.java file.
[[image: Jigsaw_m-i.j.png]]
[[image: Jigsaw_m-i.j.png]]
-
Project can have also dependency on another JDK 9 EA modular (module-info.java) NB project. Use Project Properties | Libraries customizer to add JDK 9 EA project under Modules tab using Add Project... button.  
+
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.
 +
 
 +
[[image: Jigsaw_Libs.png]]
 +
 
 +
This customizer was redesigned from previous NetBeans versions to adapt to coexistence of modulepath and classpath in JDK 9.
 +
 
 +
=== JUnit tests ===
 +
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 [https://mail-archives.apache.org/mod_mbox/ant-dev/201604.mbox/%3CBBC416D5-5553-42DC-A797-E9F93118E24A@oracle.com%3E thread: JUnitTask + JDK9 question]
 +
 
 +
[[image: JunitTestsInModule.png]]
 +
 
 +
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:
 +
 
 +
[[image:Junit_in_Module.png]]
 +
 
 +
module_info.java looks like following:
 +
 
 +
[[image:Module_info_junit.png]]
 +
 
 +
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
 +
 
 +
== Maven Projects ==
 +
With release of [http://mail.openjdk.java.net/pipermail/jigsaw-dev/2016-October/009851.html 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'''.<br/>
 +
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.<br/>
 +
It is also possible to add declared dependencies to module_info.java via a context action on the dependency node.
 +
 
 +
[[image:add_dependency_2_nodule_info.png]]
 +
 
 +
==== Unit testing ====
 +
Unit testing is possible as of Apache Maven Compiler Pluging v 3.6.1
 +
 
 +
=== What does not work  ===
 +
NetBeans Maven support is under development to provide other productivity features for Maven projects.
 +
 
 +
==== maven-javadoc-plugin ====
 +
* failures and warnings in jar(error), javadoc(warning), aggregate(error)
 +
 
 +
==== maven-war-plugin, maven-ear-plugin ====
 +
* needs to detect new version scheme
 +
* and maybe some other plugins depending on maven-archiver
-
[[image: Jigsaw_Libs.png]]
 
 +
see also https://cwiki.apache.org/confluence/display/MAVEN/Java+9+-+Jigsaw
== Other Features ==
== Other Features ==
Line 68: Line 144:
<span id="jdk9_runtime"></span>
<span id="jdk9_runtime"></span>
==Running NetBeans on JDK9 EA as run time Java platform==
==Running NetBeans on JDK9 EA as run time Java platform==
-
It is possible to try this NetBeans build run on JDK9 EA build. Use it with care as following command line switches might not be complete. Command lines for running NetBeans JDK 9 branch build on top of JDK9
+
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.
-
====Linux====
+
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.
-
<pre> $ bin/netbeans --jdkhome ~/jigsaw_b96 -J-XaddExports:java.desktop/sun.awt=ALL-UNNAMED -J-XaddExports:java.base/jdk.internal.jrtfs=ALL-UNNAMED \
+
-
-J-XaddExports:java.desktop/java.awt.peer=ALL-UNNAMED -J-XaddExports:java.desktop/com.sun.beans.editors=ALL-UNNAMED -J-XaddExports:java.desktop/sun.awt.im=ALL-UNNAMED \
+
-
-J-XaddExports:java.desktop/com.sun.java.swing.plaf.gtk=ALL-UNNAMED -J-XaddExports:java.management/sun.management=ALL-UNNAMED
+
-
</pre>
+
-
====Mac OSX====
+
-
<pre> $ bin/netbeans --jdkhome ~/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home -J-XaddExports:java.desktop/com.apple.eawt=ALL-UNNAMED \
+
-
-J-XaddExports:java.desktop/sun.awt=ALL-UNNAMED -J-XaddExports:java.base/jdk.internal.jrtfs=ALL-UNNAMED -J-XaddExports:java.desktop/apple.laf=ALL-UNNAMED \
+
-
-J-XaddExports:java.desktop/java.awt.peer=ALL-UNNAMED -J-XaddExports:java.desktop/com.sun.beans.editors=ALL-UNNAMED -J-XaddExports:java.desktop/sun.awt.im=ALL-UNNAMED \
+
-
-J-XaddExports:java.management/sun.management=ALL-UNNAMED
+
-
</pre>
+
-
====Windows====
+
-
<pre> bin\netbeans.exe --jdkhome "C:\Program Files\Java\jdk-9" -J-Djdk.launcher.addexports.0=java.desktop/sun.awt=ALL-UNNAMED -J-Djdk.launcher.addexports.1=java.base/jdk.internal.jrtfs=ALL-UNNAMED -J-
+
-
Djdk.launcher.addexports.2=java.desktop/java.awt.peer=ALL-UNNAMED -J-Djdk.launcher.addexports.3=java.desktop/com.sun.beans.editors=ALL-UNNAMED -J-Djdk.launcher.addexports.4=java.desktop/sun.awt.im=ALL-UNNAMED -J-
+
-
Djdk.launcher.addexports.5=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED -J-Djdk.launcher.addexports.6=java.management/sun.management=ALL-UNNAMED
+
-
</pre>
+
-
If you discover you need to addExport another JDK module then add it in same way as above and increase property index for it, e.g. -J-Djdk.launcher.addexports.7=...../ALL-UNNAMED
+
<span id="nb_faq"></span>
<span id="nb_faq"></span>
 +
====Changing NetBeans JDK runtime platform====
====Changing NetBeans JDK runtime platform====
How to change a JDK NetBeans uses for runtime is specified [[FaqJdkHome]] or in [[FaqNetbeansConf]].
How to change a JDK NetBeans uses for runtime is specified [[FaqJdkHome]] or in [[FaqNetbeansConf]].
 +
 +
-->

Current revision as of 08:28, 21 July 2018

NetBeans has been donated by Oracle to Apache, where it continues to be actively developed. Go to netbeans.apache.org for the latest details, go to https://netbeans.apache.org/download/nb90 in particular.


Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo