Home | Back | Contents | Next

# BSF Bean Scripting Framework

BSF is the Apache "Bean Scripting Framework". It is generic framework that allows many scripting languages to be plugged into an application. It shields the application from knowledge of how to invoke the scripting languages and their APIs, via adapter "engines".

BeanShell supports the BSF API by providing the necessary adapter. This means that BeanShell can be used as a scripting language for any BSF 2.3 capable application simply by dropping the bsh JAR file into the classpath.

Prior to version 2.3, BSF was maintained by IBM. To get BeanShell to work with older versions of BSF you must use the older bsh-bsf-1.2x.jar file which includes the adapter class for the previous ibm packaged BSF API. You must also explicitly register the BeanShell adapter with older versions of BSF. Here is an example of how to do that:

    import com.ibm.bsf.*;

    // register beanshell with the BSF framework
    String [] extensions = { "bsh" };
    BSFManager.registerScriptingEngine(
        "beanshell", "bsh.util.BeanShellBSFEngine", extensions );

See http://jakarta.apache.org/bsf/ and http://oss.software.ibm.com/developerworks/projects/bsf for more information about BSF.

## Ant

This section needs to be updated. I'm not sure what versionf of Ant use the new and which use the old BSF API.

Ant 1.5+ has explicit support for BeanShell as a BSF scripting language. The BeanShell JAR file includes the necessary BSF adapter. You must simply specify language="beanshell" in your script tags.

### Installation

To use BeanShell within Ant you must do two things:

1. Add the BSF bsf.jar file to ANT_HOME/lib or the classpath.
2. Add the BeanShell bsh.jar file to ANT_HOME/lib or the classpath.

You can then run scripts from a file, or in-line like so:

    <project name="testbsh" default="runscript" basedir=".">
        <target name="runscript">

            <!-- Run script from a file -->
            <script language="beanshell" src="myscript.bsh"/>

            <!-- Run script in-line -->
            <script language="beanshell">&lt;![CDATA[
                for(int i=0; i<10; i++ )
                    print( "i="+i );
            ]]&gt;</script>

        </target>
    </project>

Home | Back | Contents | Next