Example example_addExports_manifest
Part of the full Java 9 Jigsaw modules example suite.
|
Authors
Originally written by Martin Lehmann, Kristine Schaal and RĂ¼diger Grammes (cf. original repository). Migrated for Java Modules support documentation of Apache MavenTM in the course of the Maven Support & Care program by Gerd Aschemann (and other team members) as forked repository. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. |
What is this example about?
Module Dependency Graph, created with DepVis
Example shows …
how to use --add-exports in a manifest file for the Java launcher.
We use Add-Exports in the manifest file of modmain to gain access to internal java.base classes (without a command line option)
For this to work
-
modmain has to be started as an executable jar
-
Add-Exports must be specified in the manifest file of modmain
-
modmain has to be in the unnamed module
|
Don’t try this at home
This example demonstrates an anti-pattern.
Using These flags should only be used for testing scenarios where you need test-only dependencies (like JUnit) without polluting production module descriptors. For a realistic example of proper usage, see Issue #5: Realistic testing example. Better alternatives: Declare proper See also: Why you shouldn’t use --add-exports. |
Output
This example uses golden master testing to ensure output consistency.
The expected output is compared with actual output using verify.sh.
Expected Output
Do you want to know a secret: jdk.internal.misc.SharedSecrets
from A
Do you want to know a secret: jdk.internal.misc.SharedSecrets
from A