It helps, thx.
Do you think this will also handle both the cases where classpath is defined
in <taskdef> and
mytask.jar is in ANTHOME\lib or elsewhere?
if (this.getClass().getClassLoader() instanceof AntClassLoader){
AntClassLoader antClassLoader =
(AntClassLoader)this.getClass().getClassLoader();
taskClasspath = System.getProperty("java.class.path") + ";" +
antClassLoader.getClasspath();
}
else {
taskClasspath = System.getProperty("java.class.path");
}
Path classpath = new Path(getProject());
classpath.setPath(taskClasspath);
javaTask.setClasspath(taskClasspath);
Originally when I started it, I didn't want to wrap it with <java>. My jar
file has some external dependencies on JAXB, Spring etc. I can only succeed
when I copy it to Ant/lib. Injecting my own classpath into Ant class loader
is too challenging for me. I believe it is quite common situation for task
writer. I am interested to learn how to do it too if possible.
thanks again.
Peter Reilly-2 wrote:
>
> The classpath attribute is not available to the created task.
>
> In the task one can use MyTask.class.getClassLoader() to
> get the classloader that loaded the task.
> If this is of type AntClassloader, one can use
> AntClassloader.getClassPath()
> to get the path used in the loader.
>
> However there are a number of issues with this:
> - the MyTask may be in a system classpath, or other classpath - in which
> case, the classloader seen will not be the classloader used by
> <taskdef>
> - there must be other means to achive the same goal.
> - for example keep a reference to the path use use this refernce for
> the <java> task.
>
> Peter
>
>
> On 7/30/07, stanS <[EMAIL PROTECTED]> wrote:
>>
>> Lets say I have a taskdef in the build.xml
>> <taskdef name="mytask"
>> classname="MyTask"
>> classpath="path-to/my.jar" />
>>
>> How do I get the 'classpath' part in the custom task that derived from
>> Ant
>> Task class?
>> Could you point me to the right API?
>>
>> I want to use that classpath back with a 'java' task.
>>
>> Thanks
>> Stan.
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Getting-classpath-attribute-of-custom-task-tf4171205.html#a11866788
>> Sent from the Ant - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/Getting-classpath-attribute-of-custom-task-tf4171205.html#a11883604
Sent from the Ant - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]