ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Upayavira ...@odoko.co.uk>
Subject Re: Configuring a custom task
Date Thu, 31 Mar 2005 11:51:21 GMT
Upayavira wrote:
> Yves Martin wrote:
> 
>> Upayavira <uv@odoko.co.uk> writes:
> 
> 
>>> 1) Every time I use my task, I have to pass the task the classpath
>>> definition, as the task needs to create a new classloader with which 
>>> to run
>>> my application. Is there a way to remove the necessity to mention the
>>> classpath, deriving it from the one used within the <taskdef>?
>>
>>
>>  I know only one: put your jar with the compiled class and a antlib.xml
>>  resource (or a property file) in the ANT_HOME/lib directory.
> 
> 
> That is exactly what I want to avoid - I'm interfacing to another system 
> that has 30 or more jars, so putting them into the ANT_HOME/lib is just 
> not practical. That's why I want to get hold of the classpath used in 
> the taskdef, from within the Task, so that I don't have to specify it 
> against the task itself.

In this case, I've been really stupid. Ant uses the classpath definition 
within the taskdef to create an AntClassLoader to load my custom task. 
Therefore, the task itself is running in a classloader that has access 
to all of the classes in my application! I don't need to create my own 
classloader or anything - just invoke the classes as I would in any 
normal application, without reflection or anything. Couldn't be simpler! 
Oh well.

>>> 2) The application that the task is invoking requires a system 
>>> property to be
>>> set. So my task takes in a property 'config', and sets the system 
>>> property
>>> before invoking the application. But again, this needs to be done every
>>> time. Is there (a) a way to set a system property once that will 
>>> effect all
>>> tasks or (b) would someone recommend a specific way to provide this
>>> configuration just once, e.g. set a property, and have the task 
>>> always look
>>> for a property of that name. Is there a convention here?
>>
>>
>>  I'm not sure to have well understand your idea but you may move your 
>> 'propery'
>>  task out of the target - so it is common to all targets.
> 
> 
> Yes, I can define a property once, and I presume I can get at that 
> property from within the Task. Now, is it reasonable practice for a task 
> to always check for a specific property? With that property name 
> embedded into the task itself?

I'm going to just assume a specific property name by default, and let 
the user override the value if they choose.

Regards, Upayavira

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


Mime
View raw message