Java 9 options --add-exports vs. -XaddExports not recognized
java, java-9
Solution
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.
Problem
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 ;)