BeanShell unleashed

I'm a big fan of BeanShell.

Not only I enjoy the fact that this was the first scripting language available for the Java platform, as I really enjoy the phenomenal possibility of allowing the users of my software to make changes.

Phenomenal is indeed a suited word. The potential of BeanShell is unleashed on the fact that after a given software is compiled it gets very complicated for end-users to customize a tool. So, this nifty scripting language does what is needed.

There is however one bogging weakness. There is no proper IDE available for writing code in BeanShell, let alone an IDE that allows integrating the scripting language directly onto the libraries from our software. You get code that anyone can modify with a simple text editor and at the same time abdicate the comfort of modern day development environments since not so many folks play around with this kind of scripted language.

I've been dwelling with this IDE problem for more than two years now across different products being developed. Tried different approaches but the result was still lacking in terms of quality, until today. :-)

For a while now that I imagined how it would be possible to combine an IDE (say NetBeans) with BeanShell. The basic Java language is equal to some degree on both sides, should be noted that BeanShell is no longer a developed product and the language stopped on Java 5. Still, what would happen if we renamed the common beanshell extension (.bsh) to a .java extension?

And so I did. It was easy to configure NetBeans to accept an additional folder as source. The problem are the small differences between the two worlds. What I did was quite simple, I created a new class and then dropped the code from a BeanShell script inside.

Eventually, I noticed that it was possible to parse and change the lines of the script file in RAM, modifying the Java code to be acceptable as BeanShell. Not many changes were needed:
- Removing the declaration of "package"
- Deleting "@override" sentences
- Modifying the "class" sentence to create an object of the Plugin class

After these minor changes that are automated when running a script, the Java code becomes BeanShell code. Awesome! I can keep using the same IDE while at the same writing scripts with a syntax checker and all the fancy tools that allow adding up so much code automatically nowadays.

I'm not planning in doing a separate product to demonstrate this kind of functionality in action, but if you're interested then do let me know and I will do a small prototype.

BeanShell rocks! :-)