Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 9 options --add-exports vs. -XaddExports not recognized

Tags:

java

java-9

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 ;)

like image 262
Karussell Avatar asked Oct 28 '16 20:10

Karussell


People also ask

What does -- add exports do?

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.

What does -- Add Opens do?

--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.

Where is module info Java?

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.


1 Answers

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.

like image 108
Andy Guibert Avatar answered Oct 12 '22 23:10

Andy Guibert