I played a little bit and the solution is to tweak the Ant API ... This examples works for me, but using <import> or <include> via this way is not recommended/supported ;-) Have fun - but be aware of "side effects" ...
Cheers Jan imported.xml <project name="imported"> <echo>Hello from imported file: ${ant.file}</echo> </project> build.xml <project> <script language="beanshell"> <![CDATA[ import org.apache.tools.ant.taskdefs.ImportTask; import org.apache.tools.ant.Target; // Create an initialize the <include> (which is the same as <import>, // see taskdef-mapping: http://svn.apache.org/repos/asf/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties ImportTask includeTask = project.createTask("include"); // Set the file to include includeTask.setFile("./imported.xml"); // now tweak the Ant API by setting a non-null owning Target with an empty name // http://svn.apache.org/repos/asf/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java // public void execute() { // ... // if (getOwningTarget() == null // || !"".equals(getOwningTarget().getName())) { // throw new BuildException("import only allowed as a top-level task"); // } Target helpTarget = new Target(); helpTarget.setName(""); includeTask.setOwningTarget(helpTarget); // For further execution the <import> requires to now its location, so we // pass the <script> ones. includeTask.setLocation(self.getLocation()); // and go ... includeTask.perform(); ]]> </script> </project> -----Ursprüngliche Nachricht----- Von: SteveB [mailto:x1...@passeridae.de] Gesendet: Sonntag, 25. November 2012 14:08 An: dev@ant.apache.org Betreff: include via script task Hi all, I'm trying to call ant's include task inside a <script> element, like <script language="beanshell"> <![CDATA[ import org.apache.tools.ant.taskdefs.ImportTask; ImportTask includeTask = project.createTask("include"); includeTask.setFile("./global-properties.xml"); includeTask.perform(); ]]> </script> This fails with the error "import only allowed as a top-level task". Anyone knows how to create a "top level task" inside a <script> element ? Thanks, Steve. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org For additional commands, e-mail: dev-h...@ant.apache.org