ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rainer Noack" <>
Subject AW: How do I set a classpath for my custom task?
Date Wed, 21 Nov 2007 23:25:20 GMT
Hi Todd,

the problem is your call to Class.forName(String) in ...Engine.
This uses Engine's Classloader.

There are the following ways to add user-defined classes:

1. let the user add them to the classpath of the task's classloader or a one
of it's parents by
1.1. specify them in <taskdef>'s classpath-attribute of the migrate-task or
1.2. add them via something like the <classloader> task (see

or (IMHO better)

2. refactor the Engine class:
All methods that use Class.forName(String) should get an parameter
"ClassLoader classloader" and you should
use Class.forName(String,boolean,ClassLoader) instead.
The methods with the "old" signature should be redirected to the new methods
with classloader=Engine.class.getClassLoader().
In your task you have to create a new Classloader:
if cp is your resolved classpathref, use new
AntClassLoader(getClass().getClassLoader(),getProject(),cp) to construct the
new classpath.


Rainer Noack

-----Urspr√ľngliche Nachricht-----
Von: todd runstein [] 
Gesendet: Mittwoch, 21. November 2007 23:26
An: Ant Users List
Betreff: Re: How do I set a classpath for my custom task?

The project is non platform specific, so it can run in a container, in
a swing app, or from the command line.  The project applies schema
changes to a database.  The user creates a class that implements a
single interface, adding code that the project uses to apply the
changes.  I've currently got this working from the command line and in
a servlet (in it's init method).  I really want to create a simple to
use ant task so schema changes can be applied prior to deployment,
test runs, or whatever, but I can't get this classloader thing figured

Not sure if it's helpful, but if you need more specifics about what
I'm trying to do, the project is on sourceforge under the name
migrate4j.  If there's more info that I can provide, just let me know.


On Nov 21, 2007 1:40 PM, Martin Gainty <> wrote:
> Hi Todd-Could you provide a bit more contextWill you be implementing this
(web)application under J2EE server -or- perhaps a container such as Catalina
or Jetty?Generally these environments support their own classloader loading
algorithms depending on the capability and security characteristics of the
(web)application you will be implementing and which J2EE server and
container will be the implementor-Martin


The only "dumb question" is the one you were too afraid to ask.
Check out RouteRuler - Free software for runners, cyclists, walkers, etc.

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

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

View raw message