Friday August 11, 2006 ![]() |
JMX, SNMP, Java, etc...Daniel Fuchs blogs on JMX, SNMP, Java, etc... |
... A few weeks back A. Sundararajan was blogging about a script shell plugin for jconsole - which made it possible to use JavaScript to get at the remote JMX instrumentation. Well, what about using BeanShell?... Quoting from www.beanshell.org: BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript. Since I am not a JavaScript Guru, being able to script directly in plain Java is something that strongly appealed to me - so I decided to give it a try. In a further article Groovier jconsole! Sundar explains that
the script shell plugin makes it possible to use any language for which you have a JSR-223 script engine. Does this means that we cannot use BeanShell with jconsole yet? Well as it turns out - BeanShell comes with its own swing component - unfortunately also called JConsole :-( - and that component can be very easily embedded in jconsole using the jconsole Plugin API. So I started by taking example on the JTop demo, and less than one hour later, I was able to issue my first BeanShell command:
which lists the MBeans registered in the remote MBeanServer to which jconsole is connected.
To achieve this I had only to write two small classes: BeanShellPlugin and BeanShellPanel. This was disconcertingly easy.
The
in the beanshell interpreter, you actually list the MBeans registered in the MBeanServer of the remote VM. I then had to set up a
... and that's it! I just let NetBeans IDE build the whole stuff, then cd'd to the
That's magic! Want to try it out? Here is how to proceed:
If you don't want to use NetBeans it will be a little harder: you will
have to build the
I hope you will enjoy jconsole and BeanShell! Note You will find more on JSR-223 and BeanShell at scripting.dev.java.net and on Pat Niemeyer's Blog Update: There is now a JSR-223 ScriptEngine for BeanShell. See Sundar's article.-- daniel Tags: beanshell java jconsole jmx Posted by dfuchs ( Aug 11 2006, 04:26:56 PM CEST ) Permalink Comments [3] |
Posted by ravi joshi on September 16, 2006 at 07:53 AM CEST #
I am getting "NoClassDefFoundError: bsh/ConsoleInterface" error when I try to run JConsole with this plugin. Any idea why?
Posted by Shahrier Emon on January 09, 2008 at 06:20 AM CET #
Hi Shahrier,
It looks as if JConsole doesn't find bsh-2.0b4.jar.
You might want to check that you haven't mispelled the location of that jar in the option -J-Djava.class.path.
Here are a few things that come to my mind:
Note that you must give the path to each jar when specifying this option.
Also if you're on a windows machine the syntax will be a bit different - on windows the path separator is ';', not ':'.
-- daniel
Posted by daniel on January 09, 2008 at 10:33 AM CET #