You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Gunnar Sigurdsson <gu...@comnipoint.com> on 2005/12/29 06:14:52 UTC

taskdef classpath problem

I am using ant version 1.6.2. 

I have a custom task, com.xxx.ant.abc.GenDDL, which is stored 
in a jar file which is in the "lib" directory indicated in the 
"fileset" below.

<target name="ddl">
    <taskdef name="genddl"
             classname="com.xxx.ant.abc.GenDDL">
        <classpath>
            <fileset dir="lib">
                <include name="*.jar"/>
            </fileset>
        </classpath>
    </taskdef>
    <genddl/>
</target>

The GenDDL class depends on other jar files that are in the same 
"lib" directory. When the "ddl" target is executed, ant finds the 
GenDDL class and executes it, but it does not find resources in the 
other jar files. 

When I execute this command:

  $ ant -lib lib ddl

things work fine.

Because of our environment, I cannot require the use of the -lib option, 
or require copying of jars into $ANT_HOME, or $HOME/.ant/lib.

Is there any way for me to specify all the resources needed by the task 
within the taskdef itself?

Help will be much appreciated.

Gunnar


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


RE: taskdef classpath problem

Posted by Gunnar Sigurdsson <gu...@comnipoint.com>.
Thanks for you help. Your suggestion did the trick ...

Gunnar

On Thu, 29 Dec 2005, Rainer Noack wrote:

> [cut]
> 
> The ThreadContextClassloader is typically not your task's classloader.
> 
> You can set the  ThreadContextClassloader before instantiating
> ClassPathXmlApplicationContext.
> 
> Dont't forget to set it back to it's original value before giving back
> execution control to ant ;-)
> 
> Cheers
> 
> Rainer


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


RE: taskdef classpath problem

Posted by Rainer Noack <ra...@noacks.net>.
Hi Gunnar,

After browsing a little bit through springworkframe's web-cvs IMHO the
problem is, that 
org.springframework.core.io.DefaultResourceLoader - a baseclass of
ClassPathXmlApplicationContext -
is instantiated with it's default constructor, i.e. it uses the
ThreadContextClassloader to load resources.

The ThreadContextClassloader is typically not your task's classloader.

You can set the  ThreadContextClassloader before instantiating
ClassPathXmlApplicationContext.

Dont't forget to set it back to it's original value before giving back
execution control to ant ;-)

Cheers

Rainer


> -----Original Message-----
> From: Gunnar Sigurdsson [mailto:gunnar@comnipoint.com] 
> Sent: Thursday, December 29, 2005 7:12 PM
> To: Ant Users List
> Subject: Re: taskdef classpath problem
> 
> 
> I am not loading the resources directly, that happens as a
> side effect of GenDDL using a class from one of these other jars.
> 
> The full details are like this. Lets say GenDDL.class is in 
> GenDDL.jar, and GenDDL.class calls a class Context.class 
> which is in Context.jar, and that same jar contains a text 
> file Context.xml. Now Contex.class is a sublcass of 
> org.springframework.context.support.ClassPathXmlApplicationContext
> which is in spring.jar. The failure occurs when 
> ClassPathXmlApplicationContext tries to find Context.xml. I 
> get a FileNotFoundException.
> 
> Thanks for taking a look at this.
> 
> Gunnar
> 
> On Thu, 29 Dec 2005, Stefan Bodewig wrote:
> 
> > On Wed, 28 Dec 2005, Gunnar Sigurdsson 
> <gu...@comnipoint.com> wrote:
> > 
> > > The GenDDL class depends on other jar files that are in the same
> > > "lib" directory. When the "ddl" target is executed, ant finds the 
> > > GenDDL class and executes it, but it does not find 
> resources in the 
> > > other jar files. 
> > 
> > How are you trying to load the resources?  Are you explicitly using 
> > the classloader that has loaded your task?
> > 
> > Stefan
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 


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


Re: taskdef classpath problem

Posted by Gunnar Sigurdsson <gu...@comnipoint.com>.
I am not loading the resources directly, that happens as a
side effect of GenDDL using a class from one of these other jars.

The full details are like this. Lets say GenDDL.class is in
GenDDL.jar, and GenDDL.class calls a class Context.class which is
in Context.jar, and that same jar contains a text file
Context.xml. Now Contex.class is a sublcass of
org.springframework.context.support.ClassPathXmlApplicationContext
which is in spring.jar. The failure occurs when
ClassPathXmlApplicationContext tries to find Context.xml. I get a
FileNotFoundException.

Thanks for taking a look at this.

Gunnar

On Thu, 29 Dec 2005, Stefan Bodewig wrote:

> On Wed, 28 Dec 2005, Gunnar Sigurdsson <gu...@comnipoint.com> wrote:
> 
> > The GenDDL class depends on other jar files that are in the same 
> > "lib" directory. When the "ddl" target is executed, ant finds the 
> > GenDDL class and executes it, but it does not find resources in the 
> > other jar files. 
> 
> How are you trying to load the resources?  Are you explicitly using
> the classloader that has loaded your task?
> 
> Stefan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 


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


Re: taskdef classpath problem

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 28 Dec 2005, Gunnar Sigurdsson <gu...@comnipoint.com> wrote:

> The GenDDL class depends on other jar files that are in the same 
> "lib" directory. When the "ddl" target is executed, ant finds the 
> GenDDL class and executes it, but it does not find resources in the 
> other jar files. 

How are you trying to load the resources?  Are you explicitly using
the classloader that has loaded your task?

Stefan

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