-
CSR
-
Resolution: Approved
-
P3
-
None
-
minimal
-
The change documents JAR manifest attributes already present in the platform.
-
File or wire format
-
JDK
Summary
Document the JDK-specific JAR file attributes Add-Exports
, Add-Opens
and Enable-Native-Access
in the JAR file specification. These attributes are supported in the main section of the JAR manifest for stand-alone applications deployed as executable JAR files.
Problem
JEP 261 ("Module System") defined the JDK-specific JAR-file manifest attributes "Add-Exports
" and "Add-Opens
" to allow code in the executable JAR file access JDK internals without needing the --add-exports
and --add-opens
command line options.
JEP 454 ("Foreign Function & Memory API") defined the JDK-specific JAR-file manifest attribute "Enable-Native-Access
" to allow code in the executable JAR call restricted methods without needing to use the --enable-native-access
command-line option.
The JAR file attributes are documented in the JEPs but are not documented in the JAR file spec.
Solution
Document the "Add-Exports
", "Add-Opens
", and "Enable-Native-Access
" JAR manifest attributes in the JAR File Specification.
Specification
+++ b/closed/src/java.base/share/specs/jar/jar.md
@@ -344,6 +344,30 @@ of the manifest. They fall into the following different groups:
JAR file are defaulted to be sealed, unless they are defined
otherwise individually. See also the [Package Sealing](#package-sealing) section.
+In addition to the above Main attributes defined by the Java Platform, the JDK
+Reference Implementation also supports the following attributes for stand-alone
+applications that are bundled into executable JAR files. These attributes are
+ignored for JAR files that are not run with "`java -jar x.jar`".
+
+- Add-Exports: Updates modules to export packages to all unnamed modules. The
+ value is a space-separated list of `<module>/<package>` pairs, where
+ `<module>` is a module name and `<package>` is a package in that module. It
+ is equivalent to running with `--add-exports <module>/<package>=ALL-UNNAMED`
+ for each `<module>/<package>` pair in the list. If a pair's `<module>` is
+ not resolved, or doesn't contain the indicated `<package>`, the
+ corresponding pair is ignored.
+- Add-Opens: Updates modules to open packages to all unnamed modules. The
+ value is a space-separated list of `<module>/<package>` pairs, where
+ `<module>` is a module name and `<package>` is a package in that module. It
+ is equivalent to running with `--add-opens <module>/<package>=ALL-UNNAMED`
+ for each `<module>/<package>` pair in the list. If a pair's `<module>` is
+ not resolved, or doesn't contain the indicated `<package>`, the
+ corresponding pair is ignored.
+- Enable-Native-Access: Enables native access for all code on the classpath
+ (including the code in the executable JAR itself). The only supported value
+ is `ALL-UNNAMED`; no other module name can be given. It is equivalent to
+ running with `--enable-native-access ALL-UNNAMED`.
+
### Per-Entry Attributes