visualvm icon indicating copy to clipboard operation
visualvm copied to clipboard

Cannot find Java 1.8

Open thibaultmeyer opened this issue 5 years ago • 28 comments

Describe the bug Application cannot find Java 1.8 or higher. But Java 1.8 and Java 10 are installed on the computer. JAVA_HOME env. variable is set to the right value too.

To Reproduce Steps to reproduce the behavior:

  1. Uninstall any Oracle JRE / JDK
  2. Install OpenJDK 1.8 for windows (https://github.com/ojdkbuild/ojdkbuild)
  3. Install OpenJDK 10 for windows (https://github.com/ojdkbuild/ojdkbuild)
  4. Set JAVA_HOME to Java 1.8 directory
  5. Run VisualVM (double click on visualvm.exe)

Expected behavior Application running.

Desktop (please complete the following information):

  • OS: Windows 10 x64 (up to date)
  • JDK version 1.8.0_181-1-ojdkbuild

thibaultmeyer avatar Oct 19 '18 10:10 thibaultmeyer

Thanks for the report! Please verify that using the "--jdkhome" parameter works for you - see the First Steps section at the bottom of http://visualvm.github.io/download.html.

jisedlac avatar Oct 19 '18 11:10 jisedlac

Using --jdkhome parameter works ! VisualVM start with success

thibaultmeyer avatar Oct 19 '18 13:10 thibaultmeyer

If you want to select particular JDK permanently, you can add path to JDK to visualvm/etc/visualvm.conf file.

thurka avatar Oct 19 '18 17:10 thurka

Why doesn't VisualVM just use the the JAVA_HOME environment variable to find Java?

cawoodm avatar Jun 21 '19 14:06 cawoodm

Based on the initial report, I downloaded JDK 11 installer for Windows and JDK 8 installer for Windows from https://github.com/ojdkbuild/ojdkbuild . I installed both JDKs on WIndows 10. I downloaded VisualVM 1.4.4, unzipped it and VisualVM started just fine. There was no complain about missing Java 1.8.

thurka avatar Jan 31 '20 09:01 thurka

The problem appears to have come back, I am using adoptopenjdk 11. even if I use --jdkhome, it still can't find it, even with Visual VM2 on Windows 10.

EDIT: Nevermind, solved problem, by using '/' for system paths instead of '' on Windows, then --jdkhome recognized adoptopenjdk 11, thanks.

Borwe avatar Feb 22 '20 19:02 Borwe

Do you mean you had to use visualvm.exe --jdkhome C:/Path/To/<JDK_HOME> instead of visualvm.exe --jdkhome C:\Path\To\<JDK_HOME> on Windows? Please provide the full command to start VisualVM on your setup to make it clear for us.

jisedlac avatar Feb 22 '20 20:02 jisedlac

Do you mean you had to use visualvm.exe --jdkhome C:/Path/To/<JDK_HOME> instead of visualvm.exe --jdkhome C:\Path\To\<JDK_HOME> on Windows? Please provide the full command to start VisualVM on your setup to make it clear for us.

Yes that.

Borwe avatar Feb 23 '20 09:02 Borwe

Tested on a fresh Windows 10 installation, VisualVM 2.0 and AdoptOpenJDK 11.0.6.

Using the Windows installer, default settings, the JDK is installed to C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot, and the Windows registry is NOT updated with the JavaSoft keys.

Running visualvm.exe both from Explorer and from Command Prompt shows "Cannot find Java 1.8 or higher." dialog. This is expected because the VisualVM launcher searches for the JavaSoft registry keys on Windows, which is missing. JAVA_HOME is not read by the launcher.

Running visualvm.exe --jdkhome C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot shows "Cannot locate java installation in specified jdkhome: C:\Program" dialog. This is expected because there is a space in path (Program Files).

The correct way to run VisualVM on Windows using the AdoptOpenJDK11 installed with the default settings is visualvm.exe --jdkhome "C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot" (path to JDK in quotes).

I don't see any bug here, works exactly as designed and expected.

jisedlac avatar Feb 24 '20 13:02 jisedlac

fyi.

eg.) JAVA_HOME=C:\Program Files\AdoptOpenJDK\jdk-8.0.242.08-hotspot

Use --jdkhome option

Its works.

  • visualvm.exe --jdkhome "C:\Program Files\AdoptOpenJDK\jdk-8.0.242.08-hotspot"
  • visualvm.exe --jdkhome "C:/Program Files/AdoptOpenJDK/jdk-8.0.242.08-hotspot"
  • visualvm.exe --jdkhome "C:/Program Files/AdoptOpenJDK/jdk-8.0.242.08-hotspot/"

It does not work...

  • visualvm.exe --jdkhome "C:\Program Files\AdoptOpenJDK\jdk-8.0.242.08-hotspot\"

(...Why allow trailing slash, but disallow trailing backslash?)

Use registry

ref: https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-microsoft-windows-platforms.htm#JSJIG-GUID-47C269A3-5220-412F-9E31-4B8C37A82BFB

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft]

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit]
"CurrentVersion"="1.8"

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.8]
"JavaHome"="C:\\Program Files\\AdoptOpenJDK\\jdk-8.0.242.08-hotspot"

fukasawah avatar Mar 25 '20 07:03 fukasawah

fyi.

eg.) JAVA_HOME=C:\Program Files\AdoptOpenJDK\jdk-8.0.242.08-hotspot

Use --jdkhome option

Its works.

* `visualvm.exe --jdkhome "C:\Program Files\AdoptOpenJDK\jdk-8.0.242.08-hotspot"`

* `visualvm.exe --jdkhome "C:/Program Files/AdoptOpenJDK/jdk-8.0.242.08-hotspot"`

* `visualvm.exe --jdkhome "C:/Program Files/AdoptOpenJDK/jdk-8.0.242.08-hotspot/"`

It does not work...

* `visualvm.exe --jdkhome "C:\Program Files\AdoptOpenJDK\jdk-8.0.242.08-hotspot\"`

(...Why allow trailing slash, but disallow trailing backslash?)

Use registry

ref: https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-microsoft-windows-platforms.htm#JSJIG-GUID-47C269A3-5220-412F-9E31-4B8C37A82BFB

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft]

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit]
"CurrentVersion"="1.8"

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.8]
"JavaHome"="C:\\Program Files\\AdoptOpenJDK\\jdk-8.0.242.08-hotspot"

Yup, that was the problem I had.

Borwe avatar Mar 25 '20 14:03 Borwe

Hello,

Just one more datapoint. Using Win10, installed via Scoop (MCOfficer's bucket), which basically downloads the archive and decompresses it. And having an AdoptJdk14 hotspot installed (again just put somewhere) and using --jdkhome does not work.

But editing the JDKhome config seteting in etc/visualvm.conf works.

PAStheLoD avatar Apr 24 '20 10:04 PAStheLoD

Using --jdkhome or editing etc/visualvm.conf should have the same effect. Can you please share your command to start VisualVM using the --jdkhome switch and the working visualvm.conf file?

jisedlac avatar Apr 24 '20 12:04 jisedlac

Thanks for the quick response! Now I cannot reproduce it :o --jdkhome works. (Reverted to original .conf file and copied the path to JDK directly into powershell console and visualVM started.)

Interestingly if I supply a wrong path I get the confirmation dialog asking me whether I'd like to try the default. (And then I get the error popup.)

Hm, looking back at the console log, it seems I mistyped jdkhome before :(

Sorry for the false alarm!

PAStheLoD avatar Apr 24 '20 13:04 PAStheLoD

I just downloaded and unzipped the 2.0.1

  • visualvm_201.zip - standalone release

When I execute visualvm.exe through either double click or through a command terminal appears:

88

I can execute in peace the following commands and appears their respective results:

  • echo %JAVA_HOME%
  • java --version
  • javac --version

I am working with OpenJDK 11

Well, according with the official documentation

Download indicates:

First Steps

1. Unzip the downloaded archive. The archive already contains the top-level visualvm directory.
2. Start VisualVM by invoking the binary appropriate for your OS:
visualvm\bin\visualvm.exe or visualvm/bin/visualvm
You may provide additional options to define JDK and/or VisualVM user directory:
--jdkhome "<path to JDK>" --userdir "<path to userdir>"
3. Check out the Getting Started document, it's designed to help you start using VisualVM.

And Getting Started (referred just above in its point 3) indicates:

Starting VisualVM

To start VisualVM on Windows, run the visualvm.exe program that is in the \bin folder 
under the VisualVM install folder. On Unix or Linux use the visualvm shell script that is 
in the /bin folder under the VisualVM install folder. You may specify the JDK which runs
VisualVM and/or user directory using command line parameters or by modifying 
etc\visualvm.conf file. Example command for starting VisualVM with custom JDK and 
userdir on Windows is:

  visualvm.exe --jdkhome "C:\Software\Java\jdk1.6.0" --userdir "C:\Temp\visualvm_userdir"

Therefore:

Bug

JAVA_HOME is ignored

Solution

Two ways

One: through the command parameter:

  • visualvm.exe --jdkhome "C:\yourusername\java\openjdk\jdk-11.0.7+10"

From above, is mandatory use "" and not use =

Therefore - for example:

  • visualvm.exe --jdkhome="C:\yourusername\java\openjdk\jdk-11.0.7+10"is invalid - it uses =

Two: in the etc\visualvm.conf file - almost in the bottom add:

  • visualvm_jdkhome="C:\yourusername\java\openjdk\jdk-11.0.7+10"

From above, is mandatory use "" and use =

I hope it helps for all developers arriving to this thread.

manueljordan avatar May 04 '20 19:05 manueljordan

Another data point:

I have various flavours of JDK 8, 11 and 15 installed on macOS 10.15.6:

% /usr/libexec/java_home -V
Matching Java Virtual Machines (7):
    15, x86_64:	"OpenJDK 15"	/Library/Java/JavaVirtualMachines/openjdk15/Contents/Home
    11.0.8, x86_64:	"OpenJDK 11.0.8"	/Library/Java/JavaVirtualMachines/openjdk11-openj9/Contents/Home
    11.0.8, x86_64:	"GraalVM CE 20.2.0"	/Library/Java/JavaVirtualMachines/openjdk11-graalvm/Contents/Home
    11.0.8, x86_64:	"OpenJDK 11.0.8"	/Library/Java/JavaVirtualMachines/openjdk11/Contents/Home
    1.8.0_265, x86_64:	"OpenJDK 8"	/Library/Java/JavaVirtualMachines/openjdk8/Contents/Home
    1.8.0_265, x86_64:	"OpenJDK 8"	/Library/Java/JavaVirtualMachines/openjdk8-openj9/Contents/Home
    1.8.0_262+10, x86_64:	"GraalVM CE 20.2.0"	/Library/Java/JavaVirtualMachines/openjdk8-graalvm/Contents/Home

/Library/Java/JavaVirtualMachines/openjdk15/Contents/Home

I have JAVA_HOME set to JDK 8:

% echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/openjdk8/Contents/Home

When I try to run VisualVM.app I get this dialog saying I should use JDK 8 to JDK 14 and that Java 15 is not supported:

Schermafbeelding 2020-09-21 om 16 18 02

When I explicitly pass $JAVA_HOME via --jdkhome VisualVM does start as expected:

% /Applications/VisualVM.app/Contents/MacOS/visualvm --jdkhome $JAVA_HOME

I would expect VisualVM to default to using $JAVA_HOME by default.

breun avatar Sep 21 '20 14:09 breun

VisualVM requires the JRE.

jku1995 avatar Jan 15 '21 21:01 jku1995

VisualVM requires the JRE.

No, VisualVM requires JDK, not JRE.

thurka avatar Jan 16 '21 17:01 thurka

If you have JAVA_HOME env var set, you can run:

visualvm --jdkhome "%JAVA_HOME%"

and make a shortcut if you want launch VisualVM by double-clicking it.

pavi2410 avatar Mar 19 '21 15:03 pavi2410

`::visualvm.bat under bin

%~d0

cd %~dp0

visualvm.exe --jdkhome "%JAVA_HOME%"

pause

`

firehooper avatar Apr 12 '21 13:04 firehooper

Thanks for the report! Please verify that using the "--jdkhome" parameter works for you - see the First Steps section at the bottom of http://visualvm.github.io/download.html.

This solution worked greatly

HarishA-DotCTech avatar May 27 '21 10:05 HarishA-DotCTech

Got the same error and just used the "--jdkhome" parameter in this way: visualvm --jdkhome %JAVA_HOME%

artmotion avatar Feb 01 '22 16:02 artmotion

You may or may not need to surround your JAVA_HOME env. variable with double quotes as: visualvm --jdkhome "%JAVA_HOME%" This worked fine for me!

baseely avatar Feb 08 '22 21:02 baseely

visualvm --jdkhome $env:JAVA_HOME in powershell

lost22git avatar Sep 12 '22 16:09 lost22git

I confirm that trailing backslash produces the problem. Can someone please fix that? Thanks! :-)

mkarg avatar Mar 20 '23 16:03 mkarg

As a workaround for the trailing backslash problem, the following .bat file works for me:

@echo off

REM Remove the trailing backslash from JAVA_HOME (if it exists)
if "%JAVA_HOME:~-1%"=="\" (
  set JAVA_HOME=%JAVA_HOME:~0,-1%
)

visualvm.exe --jdkhome "%JAVA_HOME%"

lbalazscs avatar Apr 21 '23 10:04 lbalazscs

Running visualvm.exe both from Explorer and from Command Prompt shows "Cannot find Java 1.8 or higher." dialog. This is expected because the VisualVM launcher searches for the JavaSoft registry keys on Windows, which is missing. JAVA_HOME is not read by the launcher.

works exactly as designed and expected

Could you consider changing the design? What is the rationale? Why does the launcher read JavaSoft registry and not JAVA_HOME?

OndrejSpanel avatar Dec 05 '23 15:12 OndrejSpanel

--jdkhome worked for me. What I did:

  1. on the commando pronpt: cd to the bin folder, then 2 )visualvm --jdkhome <path_to_jdk>

https://visualvm.github.io/docs/command-line-options.html

ipcm27 avatar Dec 20 '23 09:12 ipcm27

Launcher was changed to also use JAVA_HOME and JDK_HOME environment variables to find JDK. This hopefuly improves the situation on Windows platform.

thurka avatar May 13 '24 06:05 thurka