ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Don Taylor <donald_l_taylor...@yahoo.com>
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"
    classname="com.yahoo.donald_l_taylor_jr.apache.ant.JavaScript">
  <classpath>
    <fileset dir="${dir.jars}">
      <include name="ant_javascript.jar" />
      <include name="bsf.jar" />
      <include name="js.jar" />
    </fileset>
  </classpath>
</taskdef>

It worked like a champ!

-- Don

--- Don Taylor <donald_l_taylor_jr@yahoo.com> wrote:
> I have an application launcher that runs an Ant script that
> ultimately
> runs my application. I'm running Ant directly, i.e.
> org.apache.tools.ant.Main. 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="org.apache.tools.ant.taskdefs.optional.Script">
>   <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:
> 
> BUILD FAILED
> 
> 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(Class.java:237)
>         at org.apache.tools.ant.Project.createTask(Project.java:439)
>         at
>
org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:83)
>         at org.apache.tools.ant.Target.execute(Target.java:152)
>         at org.apache.tools.ant.Project.runTarget(Project.java:898)
>         at
> org.apache.tools.ant.Project.executeTarget(Project.java:536)
>         at
> org.apache.tools.ant.Project.executeTargets(Project.java:510)
>         at org.apache.tools.ant.Main.runBuild(Main.java:421)
>         at org.apache.tools.ant.Main.main(Main.java:149)
> 
> 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.
> http://personals.yahoo.com


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message