Thursday, December 29, 2005

BeanShell - Another use found

BeanShell - Lightweight Scripting for Java

I'm a huge fan of beanshell as I find it to be the swiss army knife of tools for Java. It's an experimentation tool, a debugging tool, a scripting language, a configuration language, it slices, it dices.

If you aren't familiar with beanshell, download it and play around with it. It basically brings the lightweight world of dynamic programming to Java - and the code you write is Java and can access any Java.

The specific use that I wanted to mention this morning though, is that the latest version of beanshell is distributed with a servlet which allows for trivial remote access.

All you need to do is drop the bsh.jar file into your WEB-INF/lib, and add the lines:

    <servlet>
        <servlet-name>bshservlet</servlet-name>
        <servlet-class>bsh.servlet.BshServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>bshservlet</servlet-name>
        <url-pattern>/eval</url-pattern>
    </servlet-mapping>    

Now you can visit http://yourserver/yourapp/eval and you'll see a small beanshell application where you can essentially run any Java command against your web app's JVM.

Lets say e-mail isn't working from your application. Using this tool, you can simulate all of the steps of sending e-mail by hand, inside the JVM using the same classes your application would use. This gives you an easy way to get an inside-looking-out-view of your application.

Now, my next step is to do same thing, but using a language which is a bit more powerful.

2 comments:

  1. Anonymous5:40 AM

    Hi Ben,

    Why would you prefer SISC ?

    I'm a noephyte and is ignorant on the matter :-)

    You enlighten us ?

    Can it also be controlled through a servlet ?

    Thanks !

    Stephane (from France)

    ReplyDelete
  2. Stephane - what do you mean? Are you comparing scheme implementations or something?

    ReplyDelete