66

I am running Mac OSX Snow Leopard.

I've always updated Java using the regular Software Update features of Mac OSX.

I've used the Java jvisualvm tool in the past with great success.

This morning I typed jvisualvm into the command line as I often do. I got the following error:

 $ jvisualvm
 Unable to locate an executable at "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/jvisualvm" (-1)

All of the other Java tools (java, javac, jps, etc.) work just fine.

/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin indeed does not contain jvisualvm (all of a sudden).

/usr/libexec/java_home yields:

$ /usr/libexec/java_home
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

WTF?

Laird Nelson
  • 15,321
  • 19
  • 73
  • 127
  • 2
    Try /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/jvisualvm – Paul Tomblin Nov 09 '12 at 16:43
  • No dice: ` /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/jvisualvm Unable to locate an executable at "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/jvisualvm" (-1)` – Laird Nelson Nov 09 '12 at 16:44
  • @LairdNelson same here :( this is very weird. I downloaded the VisualVM by hand and it works, sort of. It does not connect to any app to profile for example. – Eugene Nov 12 '12 at 09:38
  • You know I'm having a similar problem. I think the root cause is some VisualVM but on OS X 10.8.3 + JDK7. VisualVM fires up but complains "attach: task_for_pid(330) failed (5)" on the PID that is my eclipse. If I remove eclipse and try again, it succeeds in finding the running java processes on Local. – Bob Kuhar Apr 16 '13 at 21:15

9 Answers9

32

Seems like a mixup of links; the /usr/bin/jvisualvm symlink points to something that does not exist (as people pointed out above). Apparently the jvisualvm executable (stub) exists and the way to fix this for now is to execute:

cd /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin

sudo ln -s /System/Library/Java/Support/VisualVM.bundle/Contents/Home/bin/jvisualvm .

This requires sudo privileges and creates the missing symlink, pointing to the VisualVM bundle. No idea why it happened but upgrading to latest XCode 4.5.2 did not fix this for me automatically. I am running MacOS X 10.7.5 and java 1.6.0_37

thanosa75
  • 457
  • 3
  • 5
28

It seems the supporting bundle got removed upon update. https://discussions.apple.com/thread/4474992?start=0&tstart=0

Download the bundle to use as a workaround. http://visualvm.java.net/download.html

EDIT:

Use this download link: https://java.net/projects/visualvm/downloads/download/release132/VisualVM_132.d‌​mg

pyrospade
  • 7,870
  • 4
  • 36
  • 52
kaimerra
  • 331
  • 3
  • 4
  • 1
    The latest .dmg bundle (1.3.7) doesn't seem to work with the latest stock Java-6 on OSX 10.9.1. It complains: `LSOpenURLsWithRole() failed with error -10810 for the file /Applications/VisualVM.app` – alboko Feb 13 '14 at 21:57
  • 6
    replying to myself: version 1.3.5 still works on Mavericks. Download it from [https://java.net/projects/visualvm/downloads/download/release132/VisualVM_132.dmg](https://java.net/projects/visualvm/downloads/download/release132/VisualVM_132.dmg) and run the update to download the latest engine. – alboko Feb 13 '14 at 22:13
22

I downloaded the visualvm (.dmg from java.net) and that works for me on my Mountain Lion.

enter image description here

screen shot of VisualVM Download page with specific option for Mac OS X application

user1338062
  • 11,939
  • 3
  • 73
  • 67
hko19
  • 1,054
  • 4
  • 16
  • 25
  • Virtualvm is actually more visually appealing than jconsole and offers more capability if you want to do profiling. – hko19 Nov 06 '13 at 19:26
15

For JDK 9+ users

Starting with JDK 9, Visual VM will not be included with Oracle JDK. Developers who would like to use Visual VM with Oracle JDK 9 or later can get it from the Visual VM open source project site.

Abdullah Khan
  • 12,010
  • 6
  • 65
  • 78
3

If you are already using NetBeans, another workaround is to use its profiler. In version 7.3:

  • Start the Java application from the command line, desktop or .

  • In NetBeans, choose Profile > Attach Profiler.

  • Select Attach to: <external Application>.

  • Specify the desired analysis options.

  • Click the Attach button.

  • Choose the target application.

Profiler dialog

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
3

VisualVM is also available as a standalone application. you can install it from https://visualvm.github.io/download.html

Kang
  • 169
  • 1
  • 5
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – gehbiszumeis Nov 13 '19 at 08:40
2

The Visual VM binary path for JDK 1.8 in macOS Mojave is

/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/bin/jvisualvm

Basically,

/Library/Java/JavaVirtualMachines/<JDK_DIR>/Contents/Home/bin/jvisualvm
Aditya Vikas Devarapalli
  • 3,186
  • 2
  • 36
  • 54
1

I can only run the .app version of JVisualVM on my mountain lion MBP

open /usr/share/java/Tools/Java\ VisualVM.app
David
  • 11
  • 1
  • Could you add some explanation on why? – J.A.I.L. Nov 09 '12 at 21:53
  • 1
    That also does not work for me; attempting to open it just briefly launches...launches nothing, really. Investigating the underlying `jvisualvm` symlink I see that it points back to the same failed location: `s -al /usr/share/java/Tools/Java\ VisualVM.app/Contents/MacOS/jvisualvm lrwxr-xr-x 1 root wheel 97 Aug 2 2010 /usr/share/java/Tools/Java VisualVM.app/Contents/MacOS/jvisualvm -> /System/Library/Frameworks/JavaVM.framework/Resources/VisualVM.bundle/Contents/Home/bin/jvisualvm` – Laird Nelson Nov 09 '12 at 22:05
  • I'm not sure why, I guess someone at apple got confused by all the links and deleted something. – David Nov 11 '12 at 21:06
  • @Laird, my .app file looks different: `ls /usr/share/java/Tools/Java\ VisualVM.app/Contents/MacOS JavaApplicationStub` but following the dots led me to this executable which, again, works for me from command line. `/System/Library/Java/Support/VisualVM.bundle/Contents/Home/bin/jvisualvm` for the record `java -version java version "1.6.0_37"` – David Nov 11 '12 at 21:08
  • 1
    WFM. Before I found this answer I found a man page on the Apple developer site (http://bit.ly/T0689b) that said jvisualvm was part of the Xcode command-line tools, so I launched Xcode and did an update of the Command Line Tools (Preferences -> Downloads -> Command Line Tools -> Update). Perhaps that is required? – Randall Schulz Nov 12 '12 at 17:10
-3

Sometimes it is very simple... you need to install visualvm via

sudo apt-get install visualvm

For locating the files, use

dpkg -L visualvm
Sarah
  • 7
  • 1