Skip to content
 
 

Repository files navigation

BeanShell - Simple Java Scripting

License Build workflow codecov coverity Known Vulnerabilities

The official and active project home for BeanShell.

NOTICE: Pending new release

The only recommended version is a manual build of the main branch. Support for legacy releases reached end-of-life; only issues and pull requests against main will be accepted.

The next release will be BeanShell 3.0, as the development roadmap outlines. It was decided that the next release would be a production-ready major version with all outstanding issues resolved to encourage community involvement and testing.

Most of the outstanding issues were imported from Sourceforge, where they were reported many years ago and are now orphaned without owners. The majority has already been resolved on main. An earnest call goes out for assistance in processing these issues to verify whether they are still valid, reproducible, or already resolved.

New language enhancements remain open for comments and discussion.

Items identified as out of scope for 3.0 are scheduled for the next release.

  • StrictJava compliance, unit tests, and outstanding issues
  • Updated documentation. The discussions double as future documentation.

Introduction

BeanShell is a small, free, embeddable Java source interpreter written in Java with object scripting language features. BeanShell executes standard Java syntax dynamically and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.

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 various applications, including rapid prototyping, user scripting extension, rules engines, configuration, testing, dynamic deployment, embedded systems, and 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 work with Java objects and APIs to manipulate Java applications 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.

License

Starting with version 2.0b5, BeanShell is licensed under the Apache License, version 2.0. See LICENSE for details and the NOTICE file for required attributions.

Download

Source code

The development branch is main, and it is currently recommended that you use that version. To build, pull the project, and run the maven command.

$ mvn install

Building BeanShell requires JDK 8 or newer. The resulting JAR targets Java 8 and runs on Java 8, Java 11, Java 17, Java 21, and Java 25.

The source code releases can be downloaded from GitHub releases

Latest release:

Maven

Beanshell 3.0.0 currently only has a SNAPSHOT release published to Sonatype. To use Beanshell with Maven, add this to your pom.xml:

    <dependencies>
       <dependency>
         <groupId>org.beanshell</groupId>
         <artifactId>bsh</artifactId>
         <version>3.0.0-SNAPSHOT</version>
       </dependency>
    </dependencies>

JAR binary

You can also download the bsh.jar binary from the releases page or the link below:

If you want to execute the Beanshell User Interface, either double-click the JAR file, or run it with:

$ java -jar bsh-2.1.1.jar

For a BeanShell interactive shell, you can either use the java command:

$ java -cp bsh-2.1.1.jar bsh.Interpreter

or the supplied helper scripts bsh or bsh.bat, available under the scripts folder.

You will need Java 5 or later installed.

Build

$ mvn clean install

Contribute

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 stack trace might be particularly useful for others!

Please note only issues and pull requests made against the main branch will be considered.

Documentation

For full documentation, see the BeanShell wiki and the FAQ for frequently asked questions.

See the script migration guide for compatibility examples and the changelog for build and Java integration notices.

See the SecurityGuard guide for Java embedding examples and application-defined script policies.

The old documentation available at http://beanshell.org may also be useful.

Summary of features

  • Dynamic execution of the entire Java syntax, Java code fragments, loosely typed Java, and additional scripting conveniences.
  • Transparent access to all Java objects and APIs.
  • Runs in three modes: Command Line, Console, and Applet.
  • Works 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

  • Dynamically evaluate full Java source classes, isolated Java methods, statements, and expressions.

Scripting features

  • Optionally typed variables.
  • Scripted methods with optionally typed arguments and return values
  • Scripted objects (method closures)
  • Scripted interfaces and event handlers.
  • Lambda expressions (Java 8 syntax), usable with Java APIs without casts.
  • 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 fine-grained class reloading
  • Dynamic command loading and user command path
  • Sophisticated namespace and callstack management
  • Detailed error reporting

BeanShell Uses

  • 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.

Development road map

The current development effort focuses on releasing BeanShell 3.0. 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
  • Increase unit tests code coverage 70%
  • Resolve all critical outstanding issues and process pull requests
  • Apply uniform code style and Javadocs
  • Consider feedback from community discussions

Projects using BeanShell

Projects that we know of that are using BeanShell. Is your project not listed here? Let us know by submitting an issue.

About

beanshell (moved from apache-extras.org)

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages