Reading bootstrap class bytecode from Java 7

Alan Bateman Alan.Bateman at
Tue Dec 6 12:39:09 UTC 2016

On 06/12/2016 02:07, Ess Kay wrote:

> Are there any code snippets anywhere that demonstrate using Java 9's 
> jrt-fs.jar from within Java 8 to access Java 9 java.lang.Object?  
> Cannot find any using Google. Struggling to make this work.
Here's a code fragment that reads the bytes for java/lang/Object.class, 
just point it at the target image and it will create a URLClassLoader 
that loads from the target image's jrt-fs.jar:

String targetImage = ...
URL url = Paths.get(targetImage, "lib", "jrt-fs.jar").toUri().toURL();
URLClassLoader loader = new URLClassLoader(new URL[] { url });
FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), 
Collections.emptyMap(), loader);
Path file = fs.getPath("/modules/java.base/java/lang/Object.class");
byte[] bytes = Files.readAllBytes(file);

Existing tools might find it easier to look at the /packages tree, the 
file system has sym links to support this type of navigation when needed.


More information about the jigsaw-dev mailing list