<?xml version="1.0" encoding="UTF-8"?><html><head><title>BSF Bean Scripting Framework</title></head><body bgcolor="ffffff"><table cellspacing="10"><tr><td align="center"><a href="http://www.beanshell.org/"><img src="../images/homebutton.gif"/><br/>Home</a></td><td><a href="execscripts.html#Executable_scripts_under_Unix"><img src="../images/backbutton.gif"/><br/>Back </a></td><td align="center"><a href="contents.html"><img src="../images/upbutton.gif"/><br/>Contents</a></td><td align="center"><a href="more.html#Learning_More"><img src="../images/forwardbutton.gif"/><br/>Next </a></td></tr></table><h1>BSF Bean Scripting Framework</h1> 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". <p CLEAR="ALL"/> 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. <p CLEAR="ALL"/> 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: <p/><center><table border="1" cellpadding="5" width="100%"><tr><td bgcolor="#dfdfdc"><pre> import com.ibm.bsf.*; // register beanshell with the BSF framework String [] extensions = { "bsh" }; BSFManager.registerScriptingEngine( "beanshell", "bsh.util.BeanShellBSFEngine", extensions ); </pre></td></tr></table></center><p/> See <a href="http://jakarta.apache.org/bsf/">http://jakarta.apache.org/bsf/</a> and <a href="http://oss.software.ibm.com/developerworks/projects/bsf"> http://oss.software.ibm.com/developerworks/projects/bsf</a> for more information about BSF. <h2><a name="Ant">Ant</a></h2> <em>This section needs to be updated. I'm not sure what versionf of Ant use the new and which use the old BSF API.</em> <p CLEAR="ALL"/> 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. <h3>Installation</h3> To use BeanShell within Ant you must do two things: <ol> <li>Add the <a href="http://oss.software.ibm.com/developerworks/projects/bsf"> BSF bsf.jar file</a> to ANT_HOME/lib or the classpath.</li> <li>Add the <a href="http://www.beanshell.org/download.html"> BeanShell bsh.jar file</a> to ANT_HOME/lib or the classpath.</li> </ol> <p CLEAR="ALL"/> You can then run scripts from a file, or in-line like so: <p CLEAR="ALL"/> <p/><center><table border="1" cellpadding="5" width="100%"><tr><td bgcolor="#dfdfdc"><pre> <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> </pre></td></tr></table></center><p/> <table cellspacing="10"><tr><td align="center"><a href="http://www.beanshell.org/"><img src="../images/homebutton.gif"/><br/>Home</a></td><td><a href="execscripts.html#Executable_scripts_under_Unix"><img src="../images/backbutton.gif"/><br/>Back </a></td><td align="center"><a href="contents.html"><img src="../images/upbutton.gif"/><br/>Contents</a></td><td align="center"><a href="more.html#Learning_More"><img src="../images/forwardbutton.gif"/><br/>Next </a></td></tr></table></body></html>