If I create a jlink runtime image with e.g. Java 20:
> jlink --add-modules java.base --output runtime
> .\runtime\bin\java.exe --version
openjdk 20-ea 2023-03-21
OpenJDK Runtime Environment (build 20-ea+31-2311)
OpenJDK 64-Bit Server VM (build 20-ea+31-2311, mixed mode)
Then switch the java version on my PATH to java 19:
> java --version
openjdk 19 2022-09-20
OpenJDK Runtime Environment (build 19+36-2238)
OpenJDK 64-Bit Server VM (build 19+36-2238, mixed mode, sharing)
And then try to run the java from the runtime image with the jdwp agent, e.g.:
> .\runtime\bin\java.exe -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:1234
I get the following error message:
ERROR: This jdwp native library will not work with this VM's version of JVMTI (20.0.0), it needs JVMTI 19.0[.0].
Which is confusing because it doesn't tell me the jdwp.dll library is missing.
Looking at this with a debugger, it turns out that the jdwp.dll library from the Java I have on my PATH is being loaded instead:
ModLoad: 00007ff8`a74f0000 00007ff8`a752c000 C:\Program Files\Java\jdk-19\bin\jdwp.dll
> jlink --add-modules java.base --output runtime
> .\runtime\bin\java.exe --version
openjdk 20-ea 2023-03-21
OpenJDK Runtime Environment (build 20-ea+31-2311)
OpenJDK 64-Bit Server VM (build 20-ea+31-2311, mixed mode)
Then switch the java version on my PATH to java 19:
> java --version
openjdk 19 2022-09-20
OpenJDK Runtime Environment (build 19+36-2238)
OpenJDK 64-Bit Server VM (build 19+36-2238, mixed mode, sharing)
And then try to run the java from the runtime image with the jdwp agent, e.g.:
> .\runtime\bin\java.exe -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:1234
I get the following error message:
ERROR: This jdwp native library will not work with this VM's version of JVMTI (20.0.0), it needs JVMTI 19.0[.0].
Which is confusing because it doesn't tell me the jdwp.dll library is missing.
Looking at this with a debugger, it turns out that the jdwp.dll library from the Java I have on my PATH is being loaded instead:
ModLoad: 00007ff8`a74f0000 00007ff8`a752c000 C:\Program Files\Java\jdk-19\bin\jdwp.dll