From Java 11, how can I read the content of another runtime image?
In order to list the content of a Java runtime image, JEP 220 suggests the following solution:
A built-in NIO
FileSystem
provider for thejrt
URL scheme ensures that development tools can enumerate and read the class and resource files in a run-time image by loading theFileSystem
named by the URLjrt:/
, as follows:FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); byte[] jlo = Files.readAllBytes(fs.getPath("modules", "java.base", "java/lang/Object.class"));
This snippet works and will allow me to read the content of java/lang/Object.class
in the runtime image of the Java installation that is executing the code.
How can I get it to read the content of java/lang/Object.class
in another Java installation, given its java home?
I have read this SO answer which explains how to read a Java runtime image's content from a Java 8 runtime. Unfortunately, this won't work with newer Java runtimes, since, I believe, the filesystem for jrt:/
will always point to the current runtime image.