In Java, --add-exports and --add-opens are command-line options introduced in Java 9 to modify the access control of packages and their members when using the Java Platform Module System (JPMS) or modules.
--add-exports:
--add-exports is used to export packages and make their public types and members accessible to other modules.--add-exports is as follows:--add-exports <source-module>/<package>=<target-module>
<source-module>: The name of the module that wants to export the package.<package>: The name of the package to be exported.<target-module>: The name of the module that is allowed to access the package.--add-exports mymodule/com.example.util=othermoduleThis command allows the module "mymodule" to export the package "com.example.util" to the module "othermodule," making its public types and members accessible.
--add-opens:
--add-opens is used to open packages, which means making their types and members accessible via reflection to other modules.--add-opens is similar to --add-exports:--add-opens <source-module>/<package>=<target-module>
<source-module>: The name of the module that wants to open the package.<package>: The name of the package to be opened.<target-module>: The name of the module that is allowed to access the package via reflection.--add-opens mymodule/com.example.util=othermoduleThis command allows the module "mymodule" to open the package "com.example.util" to the module "othermodule," enabling reflective access to its types and members.
The key difference between the two is in their purpose:
--add-exports is used to grant regular access to public types and members of a package.--add-opens is used to grant reflective access to types and members of a package (e.g., using Java reflection APIs like java.lang.reflect).These options are typically used when dealing with modules and managing module boundaries to ensure that the appropriate level of access control is applied while still allowing interoperability between modules when needed. They are used when running Java applications or Java modules from the command line or in module descriptors (module-info.java files) to declare access at compile-time.
mips imshow selection expression busybox protocol-handler comparable odp.net-managed apt-get x-frame-options