Monthly Archives: September 2008

Ant Scripting

Recently I discovered an interesting task in Optional Ant Tasks, it was <script>. At the beginning, I needed add deleting the oldest files in a storage. There are no standard ant ability to do this, so I took a look at some libraries, e.g. Ant-Contrib, but in the end I selected scripts because of their comfort. Here is small example of using this task:

<script language=”javascript”>
   // here is some code

You can see “javascript” which is selected as a script language, but it doesn’t mean that we cannot use java code! We CAN, but wuth some changes. For instance, import of a class will be written as:


Also, it’s not allowed to declare variables. There is one interesting feature, when method or field name coincides with javascript keyword (if you can see thrown, it’s necessary to use quotes for that word. In my case this error was when I was trying delete a file:


Ant was angry at this snippet and said:

javax.script.ScriptException: missing name after .
operator (#48) in at line number 48

It was right to use the following line instead:


That’s all for the moment. Thanks for your attention.