Pat Niemeyer has released a beta version of BeanShell 2.0. This release shows that BeanShell is now fully compatible with Java.
- Posted by: Dion Almaer
- Posted on: September 02 2003 09:56 EDT
It can now read in ordinary .java files and BeanShell scripted classes are fully typed and appear to Java as ordinary classes.
The new version also includes static imports:
static import java.lang.Math.*;
and mix-ins. You can import the methods and fields of a Java object instance into a BeanShell namespace:
Map map = new HashMap();
importObject( map );
print( get("foo") ); // "bar"
Previous limitations on the implementation of anonymous inner classes have also been lifted, allowing BeanShell to extend arbitrary Java classes and implement abstract base classes.
Read the BeanShell 2.0 Announcement
Visit the BeanShell Home Page
- Must be a Java Web Start application ! by Franck Arnulfo on September 02 2003 13:02 EDT
- BeanShell security by maxim kramarenko on September 02 2003 16:19 EDT
- Bravo! by Brian Miller on September 02 2003 18:56 EDT
- Feedback regarding Judoscript by SUDIP BHATTACHARYA on September 03 2003 01:01 EDT
- Performance by Luke S on September 03 2003 05:04 EDT
- Another... by joost de vries on September 03 2003 06:28 EDT
- Re: BeanShell performance.... by Patrick Niemeyer on September 05 2003 16:54 EDT
- BeanShell 2.0: A Fully Java Compatible Scripting Language by David Tinker on September 04 2003 00:39 EDT
- More Free Open Source Scripting Languages For Java by Gerald Bauer on September 04 2003 19:09 EDT
I'll really enjoy it if Pat could make a Java Web Start version of BeanShell on his web site !
How I can restrict access to the internal program methods in BeanShell ? I think that this is important security requirement for many apps.
You can add permission checks that only allow code trusted code to make calls into you.
As long as beanshell isn't granted these permissions you should be ok.
This is pretty invasive but would apply equally to all scripting languages and dynamically loaded code.
I spent a few hours investigating this and I think that beanshell expects to have "AllPermission" or at least some pretty invasive permissions. It makes heavy use of reflection.
I think some changes may be necessary to make beanshell run in a hardened environment.
I investigated this and I think that beanshell needs a few doPrivilegeds() around the reflective code but still execute the reflective calls in the non-privileged context.
bean shell consoles then need to be opened in a non privileged access control context and all should be well.
Can someone give some feedback on Judoscript (http://www.judoscript.com) ? It is also a java based scripting langauge and has some high level features for doing JDBC and EJB stuff.
Does anybody know if the version 2 release features any performance improvements, I remember in this article BeanShell came out looking quite sluggish (http://www.javaworld.com/javaworld/jw-04-2002/jw-0405-scripts.html).
I would be interested in any users views on BeanShell performance in general and this new release in particular.
And there's Dynamicjava
While working for business application ISVs , I have always been intrigued by the possiblity of allowing the customer to modify the application and making it easier for them inject their specific logic into the application without them having to spend $$ for customization .
With technologies like Beanshell, DynamicJava and AspectJ, I can sense that this should be achievable ; can someone share some insight into using any of these for the purpose of application customization ?
For specific tool customization, like editors, it sounds great. But, for business applications, seems difficult to do. One would have to really constrain the reach of the scripts or create a 'little language'. Scripts, unless they have safeguards like 'strict' modes, can be very brittle. Another, problem is that script languages have very powerful scripting syntax, and so can be harder to read and maintain than normal Java. This is one great advantage of BeanShell; it is Java with scripting freedom.
There are probably more robust approaches, like Business Rule Engines, MVC frameworks, and perhaps some web service 'Orchestration' tools that present an IDE. Of course, some applications can present a visual component that allows an ISV engineer to connect components and services.
OTOH, an application can have entry points that instead of invoking compiled components, can access a script library. Thus, supplying an easily changed library, even in the field, can be cool. The edit, compile, store, deploy, cycle seems very prehistoric. We should be at quasi-compiled(?) languages like Python, Perl, etc. There is plenty of cpu cycles and network bandwidth is going up with Internet2 and other develpments. Ooops! Got into a rant.
Someone with more experience with DynamicJava will have to set me straight if I'm wrong, but after my quick look I see these differences:
1) BeanShell interpretes a superset of what DynamicJava can interpret - e.g. BeanShell (2.0) interprets standard Java source but also allows allows true loosely typed variables and method signatures, as well as method closures and other scripting language features.
2) BeanShell appears to be about half the size of DynamicJava (with even smaller subsets if you require less functionality).
3) Ironically, DynamicJava is less dynamic than BeanShell - I'd image because it generates bytecode for everything. DJ does not seem to support dynamically loaded commands or scripting language features such as the "eval()" method. BeanShell can create scripted objects and classes bound in the current scope at any time. It also has sophisticated scoping extensions such as "this.caller" that allows BeanShell command writers to write methods that have side effects in the caller's namespace.
4) DynamicJava is probably faster than BeanShell right now... again, just guessing because it generates bytecode.
5) Dynamic Java's full Java language support is probably more mature than BeanShell's interpreted classes which are only in beta-1 right now.
Author of BeanShell and the book Learning Java, O'Reilly & Associates
Certain aspects of BeanShell performance were improved significantly in version 1.3 a few months back. If invoking methods on Java classes is what you do most then BeanShell is about twice as fast as it was.
BeanShell is wide open for future performance improvements. Much of BeanShell's small size and simplicity is due to the fact that it relies almost entirely on the Java reflection API and does no bytecode generation (only the new class emulation in 2.0 requires bytecode generation). However there are several places where the architecure has been specifically designed to allow optimizations that are not yet in place. For example, resolving an ambiguous name (basically everything from a variable reference to a method call) in a namespace utilizes a name resolver abstraction that allows BeanShell to cache arbitrary information about the resolution so that it doesn't have to repeat it if the namespace hasn't changed (e.g. new variables or classes are added to the scope). This is 90% (just guessing) of what Beanshell does at runtime - aside from calling methods... (see above) - and we have hardly touched it yet.
I think there is a lot of potential for BeanShell to get very fast in the future.
Author of BeanShell and the book Learning Java, O'Reilly & Asssociates
We use BeanShell in the JDO Genie Workbench. Users can write and execute snippets of JDO code for cut and paste or data fixes or whatever. Adding this capability to an application is a huge feature and was very easy to do with BeanShell. Thanks guys!
JDO Genie - www.jdogenie.com
If anyone is interested over at the Viva! site I've put together a page listing the major free open-source scripting languages for Java (including Python, Ruby, Smalltalk, Scheme and more) @ http://viva.sourceforge.net/lang.html