Getting Java program running in Eclipse to show up in VisualVM
Asked Answered
O

4

4

I'm trying to use Java VisualVM on Windows 7 64-bit together with Eclipse Kepler and am experiencing the following issue:

I have a Java application running inside Eclipse, but when I open jVisualVM, the only item showing up in the Applications under Local is VisualVM itself.

Is it possible to have my Java application show up as well? Do I need to launch it with some command line parameter to allow VisualVM to connect? Do I need to run it outside of Eclipse?

Osteal answered 6/10, 2014 at 17:46 Comment(0)
E
5

Due to a design peculiarity in the Windows JVM's you need to run JVisualVM in the same kind of JVM as the program you want to connect to (and as the same user)

This mean, use either 32-bit or 64-bit, not one of each.

A simple way to ensure this, is to add the JVM in the JDK installation directory containing the jvisualvm executable you want to use to the JVM's known to Eclipse (in Preferences), and then change the JVM used by your project to the one in the JDK you just added. Now your application should show up in the VisualVM window when launched.

Enphytotic answered 6/10, 2014 at 17:51 Comment(4)
How can I check what "kind" of JVM I'm running in? I have "jre7" selected as the execution environment for my program and am launching jvisualvm.exe from the jdk1.7.0_11 directory...Osteal
Add the jdk1.7.0._11 directory to the JVM's Eclipse knows (in preferences) and launch your program with that instead.Brisance
Got it! I needed to add the jdk, choose it as the default, and restart Eclipse. THEN it worked. If you'd like to expand your answer a bit, I'd like to accept it. :)Osteal
Also see this answer from one of the visualvm developers: https://mcmap.net/q/541386/-how-to-execute-eclipse-under-java-visualvmBrisance
P
3

Have you tried using the VisualVM eclipse launcher ? This will automatically launch visual VM for you.

The only change is when you run your main class in eclipse, is to change the configuration to use the VisualVM launcher like this.

enter image description here

Programmer answered 6/10, 2014 at 18:6 Comment(3)
That works, yes... I'm just surprised that it doesn't work without the plugin. And it's a bit annoying that I have to chose a different launcher in the run-configuration...Osteal
yes it is annoying. And I think eclipse remembers your configuration for that main class. So if you want to later rerun that main method without visualVM, you have to go back and change the configuration again back to JDT.Programmer
Thorbjørn figured out what it takes to make things work without the plugin. Now I can just work in Eclipse as I always do and if I need to profile something, I can run jVisualVM completely independently from Eclipse and all applications running inside Eclipse show up and I can profile them as needed... I'll accept his answer since it's the more "elegant" solution as far as I'm concerned. But it's good to have yours here also for completeness. Some people might actually prefer to use a plugin, too... Definitely a big thank you and +1 for you also!Osteal
B
0

Another possible solution, in case it helps others: Restart Eclipse.

This was the first time I'd tried JVisualVM on a new computer. Eclipse was showing up in JVisualVM, just not any child processes it launched.

I was tearing my hair out, trying all sorts of other things (firewall, different JDKs...) Then this silly restart just fixed it!


Anyway if all is working well, the rules seem to be:

  • JVisualVM can attach to and monitor applications using any JDK / JRE version and the same "bit-ness".
  • For full functionality (like profiling) JVisualVM should be running on an equal or higher version of the JDK than the application

Random tip (while we're discussing bitness):

  • Browsing memory dumps is inexplicably a zillion times fastor in 64-bit. (Shame, as I still like the 32-bit's -client mode for GUI apps to get the lowest memory usage. So I'd like to also profile them that way, but unfortunately it's intolerably slow.)
Brosine answered 21/7, 2016 at 14:35 Comment(0)
O
0

Just found another, quite obscure thing that can prevent your application from showing up in JVisualVM under Windows:

JVisualVM uses your system's temp-folder (as specified by the environment variable TMP) to communicate with running applications. For security reasons, if this folder is not located on an NTFS partition where Windows can provide strict file access controls, debugging is disabled and applications won't show up in JVisualVM.

If reformatting that partition or moving your entire temp-folder is not something you want or can do, you can simply create a secondary temp-folder just for JVisualVM on an NTFS partition somewhere else and set your launch configurations in Eclipse to set the environment variable TMP to that folder. Then, simply use the following batch file to run JVisualVM and everything should work:

@Echo off
set TMP=F:\temp
start "JVisualVM" /b "C:\Program Files\Java\jdk1.7.0_76\bin\jvisualvm"

Here, you need to replace F:\temp with the location of your new temp-folder just like specified in the launch configurations and C:\Program Files\Java\jdk1.7.0_76 with your JDK install directory.

Osteal answered 21/7, 2016 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.