I downloaded the latest jdk9 build:
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+142)
Java HotSpot(TM) Server VM (build 9-ea+142, mixed mode)
When I execute
/path/jdk-9/bin/java -X
I see the option:
--add-exports <module>/<package>=<target-module>(,<target-module>)*
updates <module> to export <package> to <target-module>,
regardless of module declaration.
<target-module> can be ALL-UNNAMED to export to all
unnamed modules.
But when I try to use this option:
/path/jdk-9/bin/java --add-exports:java.base/jdk.internal.ref=ALL-UNNAMED -jar some.jar
I get:
Unrecognized option: --add-exports:java.base/jdk.internal.ref=ALL-UNNAMED
The same for -XaddExports
which I saw in some posts.
What am I doing wrong here?
Do I need a special jigsaw jdk9 distribution? I'm a bit confused about the different jdk9 versions to be honest ;)
The --add-exports option allows code in the target module to access types in the named package of the source module if the target module reads the source module. This example allows code in all unnamed modules (code on the class path) to access the public members of public types in java.
--add-opensSome libraries do deep reflection, meaning setAccessible(true) , so they can access all members, including private ones. You can grant this access using the --add-opens option on the java command line. No warning messages are generated as a result of using this option.
The module descriptor ( module-info. java ) needs to be located in the src/main/java directory. Maven will set up javac to use the appropriate module source path.
The two flags have slightly different syntax. At some point (I think it was build 9-ea+113) where the JVM switched over from -XaddExports
to the --add-exports
syntax, as part of the effort for JEP 293 which aims to achieve GNU-style syntax for command line arguments.
Current syntax:
--add-exports <module>/<module>/<package>=<target-module>(,<target-module>)*
--add-reads <module>=<target-module>(,<target-module>)*
Note: Some utilities may have trouble accepting the new --key value
style of arguments because there is a space between them, in that case you can put also put an equals sign in the middle (i.e. --key=value
) to satisfy those utilities.
Old syntax:
-XaddExports:<module>/<module>/<package>=<target-module>(,<target-module>)*
-XaddReads:<module>=<target-module>(,<target-module>)*
Unfortunately, it's very easy to miss the space to colon change. I've messed it up several times myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With