Sunday, March 7, 2010

VisualVM and JFreeChart

I work in an European project in which we are developing a set of VisualVM plugins to construct a management application. It's the same principle I've used on the VisualVM OSGi plugin: a set of MBeans in the application, and a nice GUI in the VisualVM side that uses JMX to access the MBeans.
We used JFreeChart to visualize (in the VisualVM) data captured by sensors (in the managed application).
I had some minor problems for using JFreeChart due to class loading that I detail next.

Importing JFreeChart the wrong way
If you create a regular Netbeans Module project you won't be able to import libraries. So you need to create a Module Suite (File > New Project > Netbeans Module > Module Suite), and then add the Module project of you plugin to that Module Suite (see picture below).

Then, you can go right click the project, select Properties > Libraries and get the below pop up window to add your library.

What I initially did was importing in two separate steps. First the JFreeChart library, and then JCommons which is necessary for JFreeChart. After executing my code I got a java.lang.ClassNotFoundException: Weird. Everything was imported. Well, aparently we had some classloading visibility issues here.
As previously described, I had configured the following dependencies:

MyModule -> JFreeChart
MyModule -> JCommons

Doing it the right way (well, at least in a way that works)
Adding the libraries two steps gives me two Library Wrapper Modules, which will belong to the same Module Suite. But when I added both libraries at once (resulting in just one Library Wrapper Module) and tried executing the JFreeChart code, my chart appeared and I had no longer a ClassNotFoundException. Thus, the depencency became:

MyModule -> {JFreeChart, JCommons}

I believe the above issues are the same for any other Netbeans RCP application when trying to use JFreeChart.

Just to have a sample of the nice charts that you can add, here goes a screenshot with some example charts. Library download and more info at the JFreeChart website

No comments: