You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mike McNally <m5...@works.com> on 2003/03/03 20:37:41 UTC

taskdef and class loaders

I've been setting up an ant build system for the first time, and
have run across a problem for which I *think* there may be some
provisions already.

The system being built contains code-generating tools, and then
subsequent layers that use those tools.  I'd like to wrap the
code generators in ant tags and I've been successful at doing
that, except for working out problems with the class loader.

Specifically, it seems that when my task code (i.e., my Java code
that extends the ant Task class) is loaded by a <taskdef tag to
define the new task, it's loaded by the system class loader if
my .class file is in the system classpath. If the system classpath
is empty, then the ant class loader loads the class.

Because my ant task depends on classes in a library that will
not be present when the target application runs, it's problematic
for me when the class is loaded via the system class loader, as
the task just does not work -- the library is not available to
the system classloader.  When the ant class loader loads my class,
then everything works, because all my libraries *are* available
on build.classpath.

Note that the above behavior happens regardless of the setting
of the "build.sysclasspath" property.  I have it set to "ignore",
but the system class loader is still used by <taskdef>.  I've
looked at the source code briefly but not enough to figure it
out.

I don't understand the "loaderID" parameter to <taskdef>, but
I wonder whether it might not be key to a solution.

I'm running ant 1.5.1 with JDK 1.3 if it matters.

--
[ you are my main foo ] Mike McNally -- m5@works.com