Mathematica BSF Scripting Engine
Integrating with apache-ant
You can use the
Mathematica BSF engine that ships with the
GUIKit` framework in third-party applications that support BSF.
The naming conventions to note are that BSF uses the Bean concept so object lookups in the registry only support the
Bean["id"] function and not the
WidgetReference["id"] notation of
GUIKit`. Also note that BSF will not make
language="mathematica" the default scripting language in the
<script> tag, so
<script language="mathematica"> must be used explicitly.
You need to update the
/lib/ directory of an apache-ant distribution to support
Mathematica as a script language. Copy the following four resources from the
GUIKit` AddOn's
Java/ directory and
J/Link's distribution.
bsf.jar
bsf-Wolfram.jar
JLink.jar
SystemFiles/... ( J/Link native library)
NOTE: Depending upon which version of BSF the ant or third-party tool requires, you may actually have to grab the
bsf-ibm.jar and
bsf-ibm-Wolfram.jar versions from the
Java-Alternatives/BSF/lib/ directory. Starting with apache-ant Version 1.6.x and later, the new
bsf.jar and
bsf-Wolfram.jar should be used, since these are based on the apache BSF classes, while apache-ant Versions 1.5.x and earlier require the older
bsf-ibm-* jars.
With the above files in the ant distribution's path, you should then be able to use the
<script language="mathematica"> ant task. Many of the ant properties and objects will be accessible from
Mathematica as
Bean["id"] instances, and you can also specify settings for the MathematicaBSFEngine using ant
<property> instances. The most useful one would be to specify an alternate
MathLink command line to launch the kernel than the one used by default.
Here is an optional setting for specifying the launch of the
Mathematica kernel.
<property
name="bsf_engine_Mathematica_KernelLinkCommandLine"
value="-linkmode launch -linkname 'C:\\Program Files\\Wolfram Research\\Mathematica\\5.0\\MathKernel.exe'" />
Here is an example of a complete ant build file project.
<project name="helloWorld" default="main" basedir=".">
<target name="setup">
<script language="mathematica"><![CDATA[
echo = Bean["helloWorld"] @ createTask["echo"];
Bean["main"] @ addTask[echo];
echo @ setMessage["Hello World! From Mathematica :" <>
ToString[$Version] <> " " <> ToString[10!]];
]]></script>
</target>
<target name="main" depends="setup"/>
</project>