276. Implementing SWS for a Java runtime directory
Starting with JDK 9 (JEP 220), the runtime images have been restructured to support modules and become more performant and secure. Moreover, naming stored modules, classes, and resources has received a new URI scheme (jrt
). Via the jrt
scheme, we can reference modules, classes, and resources contained in runtime images without touching the internal structure of the image. A jrt
URL looks as follows:
jrt:/[$MODULE[/$PATH]]
Here, $MODULE
is a module name (optional) and $PATH
(optional) represents the path to a certain class/resource file within that module. For instance, to point out the File
class, we write the following URL:
jrt:/java.base/java/io/File.class
In the jrt
file system, there is a top-level modules
directory that contains one subdirectory for each module in the image. So, we can fetch the proper path for SWS as follows:
private static Path jrtFileSystem() {
URI uri = URI.create("jrt...