ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Ant 1.6 API: Can't call War.addZipfileset() from JavaScript
Date Thu, 23 Jun 2005 18:56:55 GMT

I have an Ant 1.5.4 build script that doesn't work in Ant 1.6 (Ant 1.6.2 
or 1.6.5). It has some embedded JavaScript that is calling the Ant API to 
add a ZipFileSet to the War task.

What we're trying to do is dynamically add directories to the War task at 
runtime. We decided to use JavaScript to calculate which directories need 
to be added, and then modify the War task via JavaScript before the War 
task is run. Using the Ant API worked straightforward for us in Ant 1.5.4.

Below is an example build.xml file that shows what we are doing. I took 
out the logic that dynamically builds the directories to include, in order 
to keep the example simple and straightforward. (Obviously, I wouldn't use 
JavaScript to add a static, known path to the War task.)

If I add the appropriate BSF and Rhino libraries to Ant 1.5.4 and Ant 
1.6.2 and run this exact same build file, it works fine in Ant 1.5.4 but 
throws an exception in Ant 1.6.2. The exception starts out like this:

       build.xml:20: Type Error: undefined is not a function.

Pretty vague error message!

With some testing, I determined that I can't call a number of War task 
methods from JavaScript in Ant 1.6.2. These include addZipfileset(), 
addLib(), and addClasses(). Not sure if I'm doing something wrong, or if 
something changed in Ant 1.6. Any ideas? Thanks!

The build.xml file below has 2 tasks: buildWar and addWarDynamic. 
Basically we use JavaScript in addWarDynamic to modify the War task in 
buildWar before it's run. As I said, this works fine in Ant 1.5.4, but 
throws that vague exception in Ant 1.6.2.

Example build.xml file:

<project name="SelfServiceReporting" default="buildWar" basedir=".">

================================================================= -->
        <!-- make WAR file     -->
================================================================= -->
        <target name="buildWar" depends="addWarDynamic" >
        <delete file="deleteMe.war"/>
        <!-- build a .war file for the application -->
                <war destfile="deleteMe.war" webxml="junk-web.xml" update=
                        <zipfileset dir="images" prefix="gfx/included" >
                                        <include name="**/*" />
                        <classes dir="classes" />

        <target name="addWarDynamic">
                <script language="javascript">
        // get ahold of the "war" task in the "buildWar" target
        var buildWarTasks = buildWar.getTasks();
        var warTask = null; 
        for (var i = 0; i < buildWarTasks.length; ++i) {
            var aTask = buildWarTasks[i];
            if (aTask.getTaskName() == "war") {
                warTask = aTask;

        // create a ZipFileSet to hold just the reports we've specified
        var reportSet = new;
        var srcRoot = new"includeTest");
        // exclude certain files
        var xxx = reportSet.createExclude();

        // due to a bug in Ant 1.6.x, we have to set the project 
        // otherwise we get a null pointer exception in 
        java.lang.System.out.println("\nreportSet.getName()=" + 
        java.lang.System.out.println("reportSet.toString=" + 
        java.lang.System.out.println("warTask=" + warTask.toString());  
        java.lang.System.out.println("warTask.getTaskName()=" + 
        java.lang.System.out.println("about to addZipfileset()..."); 
    ]]> </script>


Important news about email communications: 

If our business rules identify sensitive information, you will receive a ZixMail Secure Message
with a link to view your message. First-time recipients will be asked to create a password
before they are granted access. To learn more about ZixMail, ZixCorp Secure Email Message
Center, and other ZixCorp offerings, please go to


The information contained in this communication may be confidential,
and is intended only for the use of the recipient(s) named above.
If the reader of this message is not the intended recipient, you
are hereby notified that any dissemination, distribution, or
copying of this communication, or any of its contents, is strictly
prohibited. If you have received this communication in error,
please return it to the sender immediately and delete the original
message and any copy of it from your computer system. If you have
any questions concerning this message, please contact the sender.

Unencrypted, unauthenticated Internet e-mail is inherently insecure.
Internet messages may be corrupted or incomplete, or may incorrectly
identify the sender.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message