Extending JVisualVM - More on Getting Started
Join the DZone community and get the full member experience.Join For Free
I'm not sure when this happened, but at some point the JDK-included
VisualVM utility became extensible. This is really great news for me.
Writing a profiler is a lot of work (although admittedly very
interesting and fun). VisualVM has become such a great tool that I
welcome the opportunity to add a plugin to it.
Oracle has provided a lot of information in this area, which I do recommend reading. Look at Getting Started extending VisualVM and a number of links at the bottom of that page. It helps a lot to get NetBeans if you don't already have it, as it has significant support built-in to develop VisualVM plugins.
Rather than repeating "getting started" info, I planned to produce an actual VisualVM plugin in this entry, but I ran into some issues with the "getting started" guide. So, this is a "getting started" update for NetBeans 7.0.1 users, especially those who have just installed it (as I have) and have not yet created any projects.
As usual, some things in the "getting started" guides don't turn out as expected. For example, the guides say to choose "Platform Manager" from the "Tools" menu; in my NetBeans 7.0.1 installation, there was no such menu item. It seems things have changed slightly. If you are using NetBeans 7.0.1, here is how I worked my way around the problem:
- "File", "New Project..."
- Under "Choose Project", choose "NetBeans Modules"
- Under "Projects", choose "Module"
- Click "Next"
- Click "Standalone Module"; the dropdown mostly likely says "NetBeans IDE 7.0.1...".
- Click on the "Manage..." button. This click will bring up the coveted Platform Manager.
- Click "Add Platform..."
- Now, rather than browse to the root folder of the VisualVM application and select that directory (Platform Manager won't let you use it), instead browse to the root folder of the JDK you are using in NetBeans, drill down into the lib directory, and select "VisualVM". Click "Next".
- If you're OK with the default name "VisualVM", click "Finish". I named mine "VisualVM 1.6u20", to identify which version I chose.
- The newly-added platform should be selected in the "Platforms:" dialog. Click "Close" and then in the "New Module" dialog, choose the VisualVM platform. Click "Next".
- Provide a Code Name Base for the project (an example is given in the dialog) and click "Finish". You will now have a new project that will be built against the registered VisualVM binary.
I noticed that once I created a project and opened it (using the above steps), the "Tools" menu in NetBeans 7.0.1 became much more populated, including a menu item called "NetBeans Platforms". Apparently it was necessary to create and open one project to populate the "Tools" menu (however, it stays populated even if you close the new project). The only problem is that I needed for it to be populated before I created my project, so that I could make it a VisualVM project. The above steps show you how to achieve this goal if you have a fresh NetBeans deployment.
Now, on to that plugin I was going to write... Coming soon.
Opinions expressed by DZone contributors are their own.