ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Don Taylor <>
Subject Re: How to dynamically modify Ant's classpath -- SOLVED
Date Tue, 30 Oct 2001 14:05:32 GMT
I'm answering my own question for the benefit of others.

After learning about class loaders, I came to the realization that if I
could get ant's class loader to load the task, it would be responsible
for loading all the classes that task references and since I provided
the appropriate classpath information in the taskdef task, it would be
able to locate the appropriate jars.

'Wrapping' ant's script task in a taskdef, like I first attempted and
is shown in the first post, didn't work because the system class loader
loads ant's script task. The system class loader is then trying to load
all the BSF tasks and fails. There's no way of delegating class finding
down, you can only delegate up. By using the -debug switch I was able
to determine the class loader ant was using to load the tasks.

So what I did was create my own script task, called javascript. I took
the source of ant's script task and copied it in verbatim to my task. I
hard-coded the language to "javascript" and removed the setLanguage()
method. I packaged the class in ant_javascript.jar. I then placed the
following in my build:

<taskdef name="javascript"
    <fileset dir="${dir.jars}">
      <include name="ant_javascript.jar" />
      <include name="bsf.jar" />
      <include name="js.jar" />

It worked like a champ!

-- Don

--- Don Taylor <> wrote:
> I have an application launcher that runs an Ant script that
> ultimately
> runs my application. I'm running Ant directly, i.e.
> Now I need to add java scripting to my Ant
> task, which requires bsf.jar and js.jar. The problem is my
> application
> launcher doesn't include these jars in the classpath when it invokes
> Ant. I could resolve that issue, but then all my users would have to
> reinstall the application, which is something I would like to avoid.
> So my question is, once Ant is up and running, is there any way I can
> add these jars to the classpath?
> One thing I did try, but didn't work, is:
> <taskdef name="javascript"
>     classname="">
>   <classpath>
>     <fileset dir="${dir.jars}">
>       <include name="bsf.jar" />
>       <include name="js.jar" />
>     </fileset>
>   </classpath>
> </taskdef>
> And then use a <javascript> tag later on in my script. I've tried it
> both with and without ant_optional.jar in the classpath. Here's the
> error I'm getting:
> C:\MOPS\bin\runmops.xml:82: Could not create task of type: javascript
> due to java.lang.NoClassDefFoundError: com/ibm/bsf/BSFException
> --- Nested Exception ---
> java.lang.NoClassDefFoundError: com/ibm/bsf/BSFException
>         at java.lang.Class.newInstance0(Native Method)
>         at java.lang.Class.newInstance(
>         at
>         at
>         at
>         at
>         at
>         at
>         at
>         at
> Total time: 7 seconds
> I'm running Ant 1.3 on Windows NT. Any help is greatly appreciated.
> Thanks!
> -- Don
> __________________________________________________
> Do You Yahoo!?
> Make a great connection at Yahoo! Personals.

Do You Yahoo!?
Make a great connection at Yahoo! Personals.

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

View raw message