The following does not work: <presetdef name="hello-there"> <echo>Hello There</echo> </presetdef> <script language="beanshell"> import org.apache.tools.ant.taskdefs.MacroInstance; import org.apache.tools.ant.BuildException; task = project.createTask("hello-there"); // error </script> This will throw a java.lang.ClassCastException at org.apache.tools.ant.ComponentHelper.createNewTask(ComponentHelper.java:462)