I have a named module that uses some --add-exports
at compile time.
How can I imply this directive without specifying it manually in the run command line ?
Compilation of named module
javac --add-exports java.base/sun.security.x509=mymodule --module-source-path src -d bin --module mymodule
Packaging as a JAR
jar -c --file=mymodule.jar --main-class=mymodule.Main -C bin/mymodule
Run
java --module-path . --module mymodule/mymodule.Main
causes :
cannot access class sun.security.x509.AlgorithmId (in module java.base) because module java.base does not export sun.security.x509 to module mymodule
- if
--add-exports
is specified for the run, it runs finejava --add-exports java.base/sun.security.x509=mymodule --module-path . --module mymodule/mymodule.Main
- if
Add-Exports
is specified in the MANIFEST.MF and the jar is run as an un-named module, it should run finejava -jar mymodule.jar
but does not. This used to work in JRE 11 and now fails in JRE 17 (latest at the moment of writing)
cannot access class sun.security.x509.AlgorithmId (in module java.base) because module java.base does not export sun.security.x509 to unnamed module @0x53bd815b
http://openjdk.java.net/jeps/261 states :
A module/package pair in the value of an Add-Exports attribute has the same meaning as the command-line option --add-exports module/package=ALL-UNNAMED
How can I specify that the export is not to ALL-UNNAMED
but mymodule
instead ? How to actually make it work ?
If mymodule is not the main class but a library used deeper, then I must specify all exports for all possible modules that I may sometimes use directly from the command line ?