Re: Reading Java 9 bootstrap class bytecode from Java 12?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Reading Java 9 bootstrap class bytecode from Java 12?

Ess Kay
Is there any way of accessing Java 9's bootstrap classes from within Java
12 to access Java 9's bootstrap classes? If run using Java 12, the snippet
below always finds the Java 12 file system rather than the required Java 9
file system.  My immediate issue is that I am inappropriately finding
java.lang.constant.Constable when searching for the implemented interfaces
of java.lang.invoke.MethodHandle in Java 9 bytecode.

String targetImage = <...Java9_HOME...>
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);
Reply | Threaded
Open this post in threaded view
|

Re: Reading Java 9 bootstrap class bytecode from Java 12?

Alan Bateman
On 14/02/2019 00:33, Ess Kay wrote:

> Is there any way of accessing Java 9's bootstrap classes from within Java
> 12 to access Java 9's bootstrap classes? If run using Java 12, the snippet
> below always finds the Java 12 file system rather than the required Java 9
> file system.  My immediate issue is that I am inappropriately finding
> java.lang.constant.Constable when searching for the implemented interfaces
> of java.lang.invoke.MethodHandle in Java 9 bytecode.
>
> String targetImage = <...Java9_HOME...>
> 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);
You are using a URLClassLoader and I assume it's delegating so you are
loading the jrt file system provider from the current runtime, not from
jrt-fs.jar in the target runtime. Running with -verbose should confirm that.

The simplest way to cross target is to specify the java.home parameter
when creating the file system, e.g:

String javaHome = <JDK 9>
FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"),
Map.of("java.home", javaHome));

-Alan