Hi,
I have 2 custom tasks defined in my own jar file (package name :
j2eeunit.ant). I try to call one of my task from the other task.
Here is my task definition in my build.xml
<taskdef name="startserver"
classname="j2eeunit.ant.StartServerTask">
<classpath>
<pathelement location="lib/j2eeunit-22-0.8.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</taskdef>
<taskdef name="runservertests"
classname="j2eeunit.ant.RunServerTestsTask">
<classpath>
<pathelement location="lib/j2eeunit-22-0.8.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</taskdef>
Here is the portion of code that I use to call the other task :
StartServerTask task;
Object o = project.createTask("startserver");
System.out.println("class = " + o.getClass().getName());
task = (StartServerTask)o;
It fails with a class cast exception .... !
Now, if I bundle my tasks in ant.jar and I removed the taskdefs, everything
works fine. It seems it is a classloader problem ...
Is there a way to solve this ? It seems that the Taskdef task uses the
AntClassLoader class to load tasks. Is that the problem ? How can I remedy
it ?
Thanks.
Vincent Massol.