You can use BeanShell interactively for Java experimentation and debugging as well as to extend your applications in new ways. Scripting Java lends itself to a wide variety of applications including rapid prototyping, user scripting extension, rules engines, configuration, testing, dynamic deployment, embedded systems, and even Java education.
BeanShell is small and embeddable, so you can call BeanShell from your Java applications to execute Java code dynamically at run-time or to provide extensibility in your applications. Alternatively, you can use standalone BeanShell scripts to manipulate Java applications; working with Java objects and APIs dynamically. Since BeanShell is written in Java and runs in the same VM as your application, you can freely pass references to "live" objects into scripts and return them as results.
Earlier versions of BeanShell (2.0b4 and earlier) were distributed under GNU Lesser General Public License (LGPL) and Sun Public License (SPL).
The currently active development snapshot branch is merge-fork-beanshell2, project default branch. To bulid, pull the project and run the maven command.
$ mvn install
Requires as a minimum JDK 8 but will build with Java 9 and Java 10 as well.
Latest release: (it is highly recommended to rather use the development snapshot)
Beanshell releases are published to Maven Central. To use Beanshell with Maven, add to to your
<dependencies> <dependency> <groupId>org.apache-extras.beanshell</groupId> <artifactId>bsh</artifactId> <version>2.0b6</version> </dependency> </dependencies>
<!-- just beanshell --> <repository> <id>bintray-beanshell-Beanshell</id> <name>bintray</name> <url>http://dl.bintray.com/beanshell/Beanshell</url> <snapshots><enabled>false</enabled></snapshots> </repository> <!-- or use JCenter --> <repository> <id>central</id> <name>bintray</name> <url>http://jcenter.bintray.com</url> <snapshots><enabled>false</enabled></snapshots> </repository>
You can also download the
bsh.jar binary from Bintray.
If you want to execute the Beanshell User Interface, either double-click the JAR file, or run it with:
$ java -jar bsh-2.0b6.jar
For a BeanShell interactive shell you can either use the java command:
$ java -cp bsh-2.0b6.jar bsh.Interpreter
or the supplied helper scripts
bsh.bat available under the scripts folder.
You will need Java 5 or later installed.
$ mvn clean install
You are encouraged to raise a Github Pull Request with any suggested improvements and fixes!
You can also raise an issue for any questions or bugs. Remember, your stacktrace might be particularly useful for others!
Please note, only issues and pull requests made against the development branch merge-fork-beanshell2 will be considered.
The old documentation available at http://beanshell.org may also be useful.
Summary of features
- Dynamic execution of the full Java syntax, Java code fragments, as well as loosely typed Java and additional scripting conveniences.
- Transparent access to all Java objects and APIs.
- Runs in four modes: Command Line, Console, Applet, Remote Session Server.
- Can work in security constrained environments without a classloader or bytecode generation for most features.
- The interpreter is small, ~400K jar file.
- Pure Java.
- It's Free!!
Java evaluation features
- Evaluate full Java source classes dynamically as well as isolated Java methods, statements, and expressions.
- Optionally typed variables.
- Scripted methods with optionally typed arguments and return values
- Scripted objects (method closures)
- Scripted interfaces and event handlers.
- Convenience syntax for working with JavaBean? properties, hashtables, and primitive wrapper types.
- Auto-allocation of variables to emulate Java properties files.
- Extensible set of utility and shell-like commands
- Dynamic classpath management including find grained class reloading
- Dynamic command loading and user command path
- Sophisticated namespace and callstack management
- Detailed error reporting
- Interactive Java - try out object features, APIs and GUI widgets - "hands on".
- Scripting extension for applications - Allow your applications to be extended via scripts in an intuitive and simple way.
- Macro Languages - Generate scripts as macros and execute them live in your VM easily.
- Education - Teach Java in a hands-on, live environment
- Expression evaluator for scientific, financial apps and rules engines - evaluate complex expressions with conditions and loops.
- Remote debugging - Embed a live, remotely accessible shell / command line in your application with just a few lines of code.
- Use BeanShell declaratively to replace properties files and replace startup config files with real scripts that perform complex initialization and setup with the full Java syntax at their disposal.
BeanShell was originally maintained by Patrick Niemeyer at http://beanshell.org/ - distributed as BeanShell (2.0b4 and earlier) were distributed under GNU Lesser General Public License (LGPL) and Sun Public License (SPL).
In 2000 the project got hosted on sourceforge which quickly saw interest in the new java scripting language grow.
2005: JSR 274: The BeanShell Scripting Language
In 2005 JSR 274 is accepted for officially defining the language but this was never completed. The current status is dormant as voted by the JCP in June 2011.
2007: Community fork beanshell2
The community forked BeanShell in May 2007 creating the BeanShell2 project hosted on google code. The new fork saw crucial fixes and updates with several releases between 2011 and 2014.
The project moved to GitHub in June 2016 after google code was discontinued and is independently maintained.
In August 2017 BeanShell decided to merge all the changes from the BeanShell2 fork back upstream ensuring that no effort was lost during this period.
2012: Move to apache-extras.org
BeanShell was proposed as an incubator project to move to Apache Software Foundation. In preparation for this, the codebase for BeanShell 2.0b4 was donated to ASF by a code grant, and the license changed to Apache License, version 2.0.
The source code was moved to http://apache-extras.org/ - a project home hosted by Google Code, that was only informally associated with Apache Software Foundation. Many of the BeanShell committers were Apache committers, and thus Apache Extras seemed a natural home.
However the project did not move into the Apache incubator, and remained at apache-extras.org as an independent project.
In March 2015 Google announced it would discontinue Google Code, which provided the hosting for Apache Extras.
2015: Move to github.com
On 2015-09-23, the BeanShell repository moved from https://code.google.com/a/apache-extras.org/p/beanshell/ to its new home on https://github.com/beanshell/beanshell/ as Google Code has been discontinued.
The project adapted an open collaborative approach using GitHub pull requests and has since grown its committer base beyond the original Apache Extra team.
http://beanshell.org/ remains available for older versions.
Development road map
Current development effort is going towards the next major BeanShell release. The following road map serves as a guide to gauge progress to the next release.
- Merge fork BeanShell2
- Support for Java 9/10 with illegal access denied
- Implement varargs
- Implement try with resources
- Implement multi-catch
- Implement interfaces: constants, static and default methods
- Implement generics parsing
- Implement final modifier
- Implement BigInteger/BigDecimal and number coercion
- Make all current unit tests pass
- Resolve all outstanding issues
- Apply uniform code style and javadocs
- Fix obvious bugs and parser errors
- Increase unit tests code coverage
Projects using BeanShell
Projects that we know of which uses BeanShell. Is your project not listed here? Let us know by submitting an issue.