visualvm fails to launch because it can't find jdk: "Cannot find java. Please use the --jdkhome switch"

Bug #657048 reported by Roger Wallace
80
This bug affects 15 people
Affects Status Importance Assigned to Milestone
visualvm (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Binary package hint: visualvm

On a default installation of Ubuntu 10.10 the OpenJava JRE is installed. Install the Sun JDK from the Ubuntu repositories and the Java monitoring tool VisualVM is bundled with it. VisualVM requires a JDK and does not work with a JRE installation of Java. The launch script for VisualVM (/usr/bin/jvisualvm) contains a line that checks for a JDK,

line 13: for j in /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun; do

This line fails to find the Sun JDK but instead attempts to launch VisualVM using the OpenJava JRE. VisualVM fails to launch and presents a popup dialog asking for a valid JDK.

By switching the order of the "Sun" and "Open" paths in line 13 the problem is fixed and VisualVM loads correctly.

for j in /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-6-openjdk; do

The Ubuntu package is: visualvm version 1.3-0ubuntu2

Tags: patch

Related branches

Revision history for this message
Roger Wallace (roger-wallace-anaeko) wrote :
Revision history for this message
Vadim Peretokin (vperetokin) wrote :

I can confirm that I had the same issue on 10.10 and using the above solution worked.

tags: added: patch
Revision history for this message
DBooth (david-dbooth) wrote :

I had the same issue on Ubuntu 10.04, and although the launch script is written differently -- the word "sun" does not appear in the 10.04 launch script -- the symptom was the same. Attempting to run jvisualvm caused:
[[
$ jvisualvm
Cannot find java. Please use the --jdkhome switch.
]]

The problem seems to be that jvisualvm is a symbolic link into the openjdk directory instead of the Sun JDK directory:
[[
$ which jvisualvm
/usr/bin/jvisualvm
$ ls -l /usr/bin/jvisualvm
lrwxrwxrwx 1 root root 39 2010-11-27 13:08 /usr/bin/jvisualvm -> ../lib/jvm/java-6-openjdk/bin/jvisualvm
$ ls -l /usr/lib/jvm/java-6-openjdk/bin/jvisualvm
-rwxr-xr-x 1 root root 2749 2010-05-03 04:31 /usr/lib/jvm/java-6-openjdk/bin/jvisualvm
]]

However, I do have the Sun jdk properly installed:
[[
$ which java
/usr/bin/java
$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2010-11-23 08:58 /usr/bin/java -> /etc/alternatives/java
$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 36 2010-11-23 08:58 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
$ ls -l /usr/lib/jvm/java-6-sun/jre/bin/java
-rwxr-xr-x 1 root root 47308 2010-09-15 04:41 /usr/lib/jvm/java-6-sun/jre/bin/java
$ java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Server VM (build 17.1-b03, mixed mode)
]]

My workaround was to explicitly use the --jdkhome option to explicitly specify the Sun JDK directory every time I run jvisualvm:

  $ jvisualvm --jdkhome /usr/lib/jvm/java-6-sun/

That made VisualVM work.

Revision history for this message
DBooth (david-dbooth) wrote :

P.S. I also added the actual error message "Cannot find java. Please use the --jdkhome switch" to the bug title, so that people can find it more easily when searching.

summary: - visualvm fails to launch because it can't find jdk
+ visualvm fails to launch because it can't find jdk: "Cannot find java.
+ Please use the --jdkhome switch"
Revision history for this message
Stuart Rossiter (monsieurrigsby) wrote :

See my comments (and earlier ones from others) in bug #577958.

I suspect that DBooth did an upgrade to Lucid like me. This would mean you'd have the Sun JDK and the Lucid version of the visualvm package which won't detect the Sun JDK properly if the OpenJDK JDK is not installed (due to the script issues discussed earlier here).

There are actually 3 alternatives:

(i) Switch to the OpenJDK fully. Install the OpenJDK JDK (package default-jdk, which sorts out update-alternatives for you). Then jvisualvm will work OK (you'll be running the OpenJDK one), but you get the Fluid errors like in bug #577958.

(ii) As specified in bug #577958, you can switch to the proper Sun jvisualvm by running /usr/lib/jvm/java-6-sun/bin/jvisualvm explicitly, or changing the /usr/bin/jvisualvm symlink to permanently point to this.

(iii) Do what DBooth did, which runs the OpenJDK jvisualvm, but with the Sun JDK backend. With this, you get the *same* Fluid error as #577958 (but, as with my comments there, this doesn't seem to affect the ability to link to running/launched Java apps.).

One possible fix for *this* bug is therefore to ensure that a Sun JDK package ensures that an update-alternatives entry for jvisualvm exists to automatically do (ii) above, so that you're either running the full Sun suite or the full OpenJDK suite (and built into update-java-alternatives as well). And then you wouldn't have to worry about all the checking in the OpenJDK jvisualvm script. Of course, this might not be considered valid if the devs want to allow the case of running the OpenJDK jvisualvm frontend with a Sun JDK backend.

Revision history for this message
Stuart Rossiter (monsieurrigsby) wrote :

The correct fix depends on a full understanding of how jvisualvm actually works.

The --jdkhome option appears to control only the JVM that VisualVM runs in, not the JVM which it monitors for Java instances. I can run the Sun VisualVM with the Sun JVM as jdkhome, and still see/monitor Java programs launched using OpenJDK. Equally, I can run the Sun VisualVM with the OpenJDK JVM as jdkhome, and monitor Java programs launched using Sun or OpenJDK JVMs.

Is the fact I can monitor both because:

a) OpenJDK, as a 'fork' of the Sun JDK, retains run-time compatibility in some way?

b) The VisualVM uses standardised JRE/JDK APIs which all JDKs should support (so I could also view stuff launched using, say, IBM's JVM)?

I assume (b), which would mean that my suggested fix is 'correct', because there is no reason to ever want to run one JDK-supplier's VisualVM using another supplier's JVM.

Daniel T Chen (crimsun)
Changed in visualvm (Ubuntu):
status: New → Confirmed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package visualvm - 1.3.2-0ubuntu1

---------------
visualvm (1.3.2-0ubuntu1) oneiric; urgency=low

  * New upstream version.
  * Drop build dependency on libnb-apisupport2-java. LP: #832764.
  * Fix jdk detection. LP: #657048.
  * Update package description. LP: #813165.
 -- Matthias Klose <email address hidden> Thu, 08 Sep 2011 13:38:19 +0200

Changed in visualvm (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
veyvr (chris-std) wrote :

This bug does not seem to be fixed:

Using Ubuntu 11.10 amd64
Installed packages:
• visualvm 1.3.2-0ubuntu1 from oneiric
• openjdk-7-demo 7~b147-2.0-0ubuntu0.11.10.1 from oneiric-updates
• openjdk-7-doc 7~b147-2.0-0ubuntu0.11.10.1 from oneiric-updates
• openjdk-7-jdk 7~b147-2.0-0ubuntu0.11.10.1 from oneiric-updates
• openjdk-7-jre 7~b147-2.0-0ubuntu0.11.10.1 from oneiric-updates
• openjdk-7-jre-headless 7~b147-2.0-0ubuntu0.11.10.1 from oneiric-updates
• openjdk-7-jre-lib 7~b147-2.0-0ubuntu0.11.10.1 from oneiric-updates
• openjdk-7-source 7~b147-2.0-0ubuntu0.11.10.1 from oneiric-updates
no java 6 installed, no sun java installed

when starting jvisualvm from terminal I get this:
––––––––––––––––––––––––––
$ jvisualvm
No jdkhome found
––––––––––––––––––––––––––

the reason is that in /usr/bin/jvisualvm , line 13 the paths for java-6-openjdk and java-6-sun are hard-coded. Without having any java 6 installed jvisualvm can not start.

How about
a) integrating java-7-openjdk
b) using the path of /etc/alternatives/javac instead/additionally

Revision history for this message
Petr Gladkikh (petrglad) wrote :

I have installed openjdk-7 and openjdk-6 on Ubuntu 12.04 LTS

And have same problem. specifying --jdkhome doesl not help (it looks like this switch is ignored):

$ jvisualvm
No jdkhome found

$ update-java-alternatives -l
java-1.6.0-openjdk-i386 1061 /usr/lib/jvm/java-1.6.0-openjdk-i386
java-1.7.0-openjdk-i386 1051 /usr/lib/jvm/java-1.7.0-openjdk-i386

$ jvisualvm --jdkhome /usr/lib/jvm/java-1.6.0-openjdk-i386
No jdkhome found

$ jvisualvm --jdkhome /usr/lib/jvm/java-1.7.0-openjdk-i386
No jdkhome found

Revision history for this message
Shannon VanWagner (shannon-vanwagner) wrote :

The /usr/bin/jvisualvm startup script (around line 13) is looking for: /usr/lib/jvm/java-6-openjdk :
sv@ubu:~$ grep -n /usr/lib/jvm /usr/bin/jvisualvm
13:for j in /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun; do

And, assuming the openjdk-6-jdk package is already installed (sudo apt-get install openjdk-6-jdk), there is no link in /usr/lib/jvm for /usr/lib/jvm/java-6-openjdk:
sv@ubu:~$ ls /usr/lib/jvm
java-1.6.0-openjdk-amd64 java-6-openjdk-amd64 java-6-openjdk-common

#Here's what worked for us:
So, to match things up and make the program work, simply create a symlink:
sv@ubu:~$ sudo ln -s /usr/lib/jvm/java-6-openjdk-amd64 /usr/lib/jvm/java-6-openjdk

Note: I am using Ubuntu 12.04 64-bit version, so you may have to adjust your symlink accordingly.

Revision history for this message
Evan (halful01) wrote :

I had this problem as well with visualvm version 1.3.2-0ubuntu2. As a workaround I remove the empty directory /usr/lib/jvm/java-6-openjdk and created a symlink in it's place that points to /usr/lib/jvm/java-6-openjdk-amd64. It seems strange that the package openjdk-6-jdk would install an empty directory, maybe they forgot to make it a symlink?

Revision history for this message
Dmitriy Balakin (0x0000.ru) wrote :

The package in the release of Ubuntu 12.04 LTS still has this bug. Check out my patch.

Revision history for this message
Dmitriy Balakin (0x0000.ru) wrote :
Revision history for this message
Khaled Blah (khaled-blah) wrote :

I had the same problem in u12.04 and the patch in #16 fixed it for me. Thanks Dmitriy!

Revision history for this message
Falko Menge (falko-menge) wrote :

I solved it using 'sudo apt-get install openjdk-6-jdk' in Ubuntu 12.04.1 LTS

Revision history for this message
John (vanuan) wrote :

So it's just a missing dependency?

Revision history for this message
John (vanuan) wrote :

Aha, it has path to openjdk hardcoded. And it doesn't support oracle jdk

Revision history for this message
Jouni "rautamiekka" Järvinen (rautamiekka) wrote :

Ubuntu Server 12.04 LTS x64, fully updated as of 2014-07-03, and still no support for Oracle Java 8 x64 installed through https://launchpad.net/~webupd8team/+archive/java. We're talking about a literal shame here on (j)visualvm's part for not supporting its own owner.

Wake up, ffs, and quit hardcoding !

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.