Java

HACK JAVA MODULE SYSTEM THROUGH COMMAND LINE

Hack Java Module System

Java provides some most important command line tags that will help to get your project to compile, test, and run. The Java Platform Module System (JPMS) contains rules to work with Java and at the same time JPMS introduces some command line operations to break them. If you are needed to access internal APIs, unforeseen modules, or can extend modules with classes of our own. The major command line options are –add-exports, –add-opens, –add-modules, –add-reads, and –patch-module.

To access internal APIs through –add-exports Option , use it as –add-exports parentmodule/childpackage= destinationmodule. Which exports the childpackage of parent module to destinationmodule. So that the destinationmodule can access all the public methods within the childpackage.If you want to set that all code from the class path can access the childpackage, then arrange the code of destinationmodule to ALL-UNNAMED.

For reflectively accessing internal APIs, we can use –add-opens option. So that in order to open a childpackage of module for deep reflection to reflectingmodule. We can use the command line arguement as –add-opens parentmodule/childpackage=reflectingmodule. Code in $reflectingmodule can hence reflectively access all types and members in $package but other modules can not. For the access of full data from package set reflectingmodule arguemnet to ALL-UNNAMED. For example: –add-opens java.base/java.lang=ALL-UNNAMED

For reflectively accessing internal APIs, we can use –add-opens option. So that in order to open a childpackage of module for deep reflection to reflectingmodule. We can use the command line arguement as –add-opens parentmodule/childpackage=reflectingmodule. Code in $reflectingmodule can hence reflectively access all types and members in $package but other modules can not. For the access of full data from package set reflecting module argument to ALL-UNNAMED. For example: –add-opens
java.base/java.lang=ALL-UNNAMED

Adding Classes To Modules can be done by –patch-moduleoption. Ie, to merge all classes into a single module at Compile time and runtime, we can use the command line option –patchmodule module=artifact merges all classes from.There is no need to add modules automatically in this, it might still need to be added with –add-modules even if we need it implicitly. Then, those classes will be added to a module with –patch-module.

The modules can be extended by using –add-module. In general, javac and java provide a command line option for explicitly defining a comma-separated list of root modules. By this, we can add modules to the module graph if they are depended, else initial modules does not depend. The –add-modules are Java EE modules, that are not resolved by default running application.

To extend the module graph, use –add-reads. i.e, in order to set the readability of a class to all set of target classes at the Compile time and runtime, which are separated by comma, we can use the command line –add-reads module=targets. It adds readability. So that the module class can access all public types in the package. By setting the target class to ALL UNNAMED, it provides access to read even the unnamed module

Author: STEPS

Leave a Reply

Your email address will not be published. Required fields are marked *