I just downloaded and tried to run VisualVM on Windows 10 with OpenJDK 8 but it failed. The fix is simple but took a few minutes to find the solution.
I downloaded VisualVM and followed the instructions:
- Unzipped to a folder om my computer
- Then, executed
visualvm_211\bin\visualvm.exe
I was, however, confronted by this error.
Not a great start. The OpenJDK Java 8 JDK is on my path – so, I was surprised. I double-checked that it was the JDK (and not just the JRE since VisualVM does not work with the JRE). That’s OK – so, I’m still surprised.
For some reason, VisualVM was not picking up the JDK installed on the system. I looked at the troubleshooting guide and decided that everything looked right but it was still not picking it up.
VisualVM does, however, let you pass in the JDK home by doing --jdkhome "<path to JDK>"
and so, I used that instead.
Doing this works great:
$ d:\apps\jlib\visualvm_211\bin\visualvm.exe --jdkhome "c:\Program Files\AdoptOpenJDK\jdk-8.0.265.01-hotspot"
Two things to note:
- Point to the directory above the
/bin
in your JDK installation - Do not end with a ‘\’ – if you do, you will get another error
I decided to throw that into a command file (jvvm.cmd
) that is stored in mu d:\tools
folder which is on the path so that I can just launch it directly without remembering the command. However, if you do something like that, remember that the JDK path is hard-coded for now.
A slightly better way is to do this if you have JAVA_HOME set in your enviornment (and it ends with a ‘\’):
1
2
set jh_no_slash=%JAVA_HOME:~0,-1%
d:\apps\jlib\visualvm_211\bin\visualvm.exe --jdkhome "%jh_no_slash%" %*
The first line reads the JAVA_HOME
and removes the slash from it. The second line expands that path and passes it to the visualvm.exe
as --jdkhome
and finally the %*
at the end passes all other parameters that you send to the jvvm.cmd
as command line parameters (except the very first which is the the call to jvvm.cmd
).
This way, if you change the JAVA version using the method here, the next time you call jvvm.cmd
, it will launch VisualVM using that JDK instead.
Ok, that’s all – now to figure out what VisualVM does!
As always, this is for me to remember what I had done. If it helps you, that’s great. If you have any other information to add, please let me know by commenting below and I will try to update the post.