## Script

### Description

Execute a script in a BSF supported language.

Note: This task depends on external libraries not included in the Ant distribution. See Library Dependencies for more information.

All items (tasks, targets, etc) of the running project are accessible from the script, using either their `name` or `id` attributes (as long as their names are considered valid Java identifiers, that is). The name "project" is a pre-defined reference to the Project, which can be used instead of the project name.

BeanShell users: This task now natively supports the BeanShell scripting language, using language="beanshell". The BeanShell engine is still required.

Scripts can do almost anything a task written in Java could do.

### Parameters

Attribute | Description | Required
language | The programming language the script is written in. Must be a supported BSF language | Yes
src | The location of the script as a file, if not inline | No

### Examples

>     <project name="squares" default="main" basedir=".">

>       <target name="setup">

>         <script language="javascript"> <![CDATA[

>           for (i=1; i<=10; i++) {
>             echo = squares.createTask("echo");
>             main.addTask(echo);
>             echo.setMessage(i*i);
>           }

>         ]]> </script>

>       </target>

>       <target name="main" depends="setup"/>

>     </project>

generates

>     setup:

>     main:
>     1
>     4
>     9
>     16
>     25
>     36
>     49
>     64
>     81
>     100

>     BUILD SUCCESSFUL

Another example, using references by id and two different scripting languages:

>     <project name="testscript" default="main">
>       <target name="sub">
>         <echo id="theEcho"/>
>       </target>

>       <target name="sub1">
>         <script language="netrexx"><![CDATA[
>           theEcho.setMessage("In sub1")
>           sub.execute
>         ]]></script>
>       </target>

>       <target name="sub2">
>         <script language="javascript"><![CDATA[
>           theEcho.setMessage("In sub2");
>           sub.execute();
>         ]]></script>
>       </target>

>       <target name="main" depends="sub1,sub2"/>
>     </project>

generates

>     sub1:
>     In sub1

>     sub2:
>     In sub2

>     main:

>     BUILD SUCCESSFUL

Copyright © 2000-2002 Apache Software Foundation. All rights Reserved.