Java 9, Jigsaw Example Suite
Written by Martin Lehmann, Kristine Schaal and Rüdiger Grammes
see https://github.com/accso/java9-jigsaw-examples
This is a example suite for Java 9 jigsaw modules. Many aspects of the new Java 9 Jigsaw modules as defined in Project Jigsaw by JSR 376 and JEP 261.
All the examples have been successfully tested with Windows (64bit), Linux and MacOSX - running Java 9, Java 10 and Java 11. Eclipse projects can be used with Eclipse Oxygen.1 4.7.1a. The three Maven examples need Maven 3.5.2 (if run with Java 9 or 10), Maven 3.6.1 (if run with Java 11). The Gradle example needs at least Gradle 5.4.1 (if run with JDK11), 4.6 (if run with JDK10) or 4.2.1 (if run with JDK9).
example_maven-project
, example_maven_blackbox
and example_maven_whitebox
only.example_gradle-project
only.env.sh
to configure JAVA_HOME
and JAVA_HOME_JDK8
and GRAPHVIZ_HOME
and MAVEN_HOME
and GRADLE_HOME
and DEPVIS_HOME
(see TODO markers)env.sh
to configure the path separator. If run on Windows, use ; (a blackslash quoting a ;). If you run all stuff on *nix, use a colon : .allclean.sh
, allcompile.sh
, allcreatevis.sh
and allrun.sh
(or all.sh
for all in one step).all.sh
for all in one step).Note that all scripts have been tested with bash only. There might be minor issues with the *.sh scripts whenever they call each other. To be sure, you should use all of these clean, compile, run, test etc. scripts in a bash.
example_.../src
. That's the module-source-path.example_.../mods
.example_.../mlib
. That's the module-path when run.example_.../amlib
. That's also the module-path, in this case containing automatic modules.example_.../classes
.example_.../patches
. Corresponding JAR files are in example_.../patchlib
.No software is ready, ever ;-) So here are some ideas left (any other feedback very welcome!):
example_spring-hibernate
because of a compile problem. See readme.md
there for details.
Needs probably Maven/Plugin updates, to be done soon.
Examples | Description | Related Examples | |
---|---|---|---|
Examples on the declaration of modules | example_naming-modules | Which naming conventions exist for modules? Which names are not allowed? | |
example_annotations | How can one specify annotations and deprecation for modules? | ||
Examples on basic module reads and exports attributes | example_requires_exports_requires-transitive_exports-to | How does requires, requires transitive and qualified exports look like? | all other examples in this section |
example_requires-static | How does requires static look like? | all other examples in this section | |
example_requires_exports | How does requires and exports look like? | all other examples in this section | |
example_requires_exports-to | How does requires and qualified exports look like? | all other examples in this section | |
example_reflection | How do reflection calls look like? | all other examples in this section | |
Examples on dynamic binding with uses/provides | example_uses-provides | How does uses-provides look like? | all other examples in this section |
example_uses-provides_uses-in-client | How does uses-provides look like, when uses is separated from the interface? | all other examples in this section | |
Examples on accessibility and (non) exported packages | example_derived_private-package-protected | What happens, when classes / packages in a module are exported, but their sub/super classes are not? | all other examples in this section |
example_exceptions | What happens, when exceptions are thrown to classes outside the module but their package is not exported? | all other examples in this section | |
example_interface-callback | What happens, when outside the module a callback implementation is called which package is not exported? | all other examples in this section | |
Examples on specificing add* options | example_addExports_manifest | How can we use --add-exports in a manifest file for the Java launcher? | all other examples in this section |
example_addReads_addExports | How can we use --add-reads and --add-exports for Javac compiler and Java launcher | all other examples in this section | |
example_addReads_addExports_reflection | How can we use --add-reads and --add-exports for reflection calls? | all other examples in this section | |
Examples on automatic modules | example_automatic-module-logging | How to automatic modules (for logging) look like? | example_splitpackage_automatic-modules |
Examples on restricting the access to resources in other modules | example_resources | Which resources in modules are accessible, which are not? | |
Examples on the split package problem | example_splitpackage | What happens when one has a split package problem at compile / at runtime? | all other examples in this section |
example_splitpackage_automatic-modules | What happens when one Automatic Module automatically reads all other Automatic Modules on the module path and hence creates an unwanted split package problem? | example_automatic-module-logging, all other examples in this section | |
Examples on resolution of modules, layers and visibility of modules between layers | example_jerrymouse | How can an "app server" JerryMouse (sic!) load and start modules, as a kind of module starter/container? | all other examples in this section |
example_resolved-modules | Which modules are resolved? Usage of jlink | all other examples in this section | |
example_layer-hierarchy | How can one create a hiearchy of layers automatically and add modules (d naming conventions)? | all other examples in this section | |
example_layer-modules-all-in-boot-layer | How does the boot layer look like containing a bunch of modules? | all other examples in this section | |
example_layer-modules-grouped-in-hierarchy | How does a small hiearchy of layers look like when one explicitely distributes a bunch of modules to these layers? | all other examples in this section | |
example_layer-modules-module-resolution | How are different versions of a module resolved depending on the setup of the layer? | all other examples in this section | |
Examples on testing | example_test | How can one achieve blackbox and whitebox testing? | all other examples in this section |
example_maven-test-blackbox | How can one achieve blackbox testing with Maven? | all other examples in this section | |
example_maven-test-whitebox | How can one achieve whitebox testing with Maven? | all other examples in this section | |
example_patch | How can we patch a module at compile / runtime? | all other examples in this section | |
Examples on Main classes | example_hiddenmain | Is it possible that one can call a Main class which is in a non-exported package? | |
Examples on access from and to the classpath (i.e. the unnamed module) | example_unnamed-module_access-from-automatic-module | Can a Automatic Module access the classpath (i.e. the unnamed module)? | all other examples in this section |
example_unnamed-module_access-from-explicit-module | Can a Explicit Module access the classpath (i.e. the unnamed module)? | all other examples in this section | |
example_unnamed-module_access-from-explicit-module-reflection | Can a Explicit Module access the classpath (i.e. the unnamed module) via reflection? | all other examples in this section | |
example_unnamed-module-reflection-illegal-access | Can the classpath (i.e. the unnamed module) access concealed packages in the JDK and what happens when the JDK "kill switch" is activated? | all other examples in this section | |
example_unnamed-module_accessing-module-path | Can the classpath (i.e. the unnamed module) access modules on the module path? | all other examples in this section | |
Examples on build systems | example_gradle-project | How can one use Gradle 4.2.1 for building a modularized project? | all other examples in this section |
example_maven-project | How can one use Maven 3.5.2 for building a modularized project? | all other examples in this section | |
Examples on porting applications from Java8 to Java9 | example_spring-hibernate | How does the migration of a Spring Boot application with a bunch of Maven plugins look like and where do we have to tweak / change in comparison to Java 8? | |
example_compile-target-jdk8 | What happens when one compiles with JDK9 with or without targeting a Java release 9 or 8? | ||
Examples on non-Jigsaw topics | example_version | How does the new Java 9 version string (cf JEP 223) look like? |
The examples have been used and tested with these tools and libraries (on Windows 10, Linux, MacOSX):
Tool | Version | Used for | Remark | Link |
---|---|---|---|---|
JDK | 9 b181, 9.0.1, 9.0.4, 10 and 11 | all examples at compile and runtime | http://jdk.java.net/9/ and http://jdk.java.net/10/ and Java 11. All open jdks should work. Tested with corretto https://aws.amazon.com/de/corretto/ | |
JDK | 1.8.0_144 | only needed for example_compile-target-jdk8 |
http://jdk.java.net/8/ | |
Maven | 3.5.2, 3.6.1 with JDK11 | Maven examples | Note that we use Maven compiler plugin 3.7.0 | https://maven.apache.org/download.cgi |
Gradle | 4.2.1 with JDK9, 4.6 with JDK10, 5.4.1 with JDK11 | Gradle example | https://github.com/gradle/gradle | |
Eclipse | 4.7.1a (Oxygen.1a) and 4.7.3a (Oxygen.3a) | all examples | https://www.eclipse.org/ | |
Junit | 4.12 | all test examples | together with Hamcrest 1.3 | |
Spring Boot, various libs | various | only in example_spring-hibernate |
refer to POM.xml in this example | |
GraphViz | 2.38 | visualizing the module graph | http://www.graphviz.org/ | |
DepVis | 0.3 | visualizing the module graph, provides the .dot file as input for GraphViz | https://github.com/accso/java9-jigsaw-depvis |
Note that these are the versions with with we have tested the example suite. Older or newer versions might also work but we did not try.
example_spring-hibernate
because of a compile problem. See readme.md
there for details.
Needs probably Maven/Plugin updates, to be done soon.
example_gradle-project
now also include a --info --stacktrace
for more info and error outputNo changes necessary
All kinds of scripts, code, environment settings etc. were checked and lots of cleanup was done. Nothing critical but looks "fresher" now. Some changes:
example_maven-test-blackbox
and example_maven-test-whitebox
example_unnamed-module_access-from-automatic-module
example_requires-transitive_exports
(obsolete as all of its contents is covered by example_requires_exports_requires-transitive_exports-to
already)No changes necessary
Now with print and visualization output like printing uses and provides, printing concealed packages, showing opens and opens-to etc. See DepVis Readme for details
example_unnamed-module-reflection-illegal-access
is new, shows the usage of the "kill switch"example_requires-static
is new, shows the usage of the "requires static"example_resources
is fixed, now works as expectedexample_jerry-mouse
limits its apps to a whitelist and only uses them, if they workexample_jerry-mouse
: Its modmain
is now an "open module" (instead of "opens pkgmain")DepVis, see https://github.com/accso/java9-jigsaw-depvis : Visualization tool for Jigsaw modules
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.