You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Christofer Jennings <bo...@gmail.com> on 2008/05/04 19:22:25 UTC

classloader problem?

I think I have a classloader problem.

I've made a custom task that looks through classes for a method annotation,
then makes a report. I've got junit tests that work in my IDE showing that
the annotations can be found. But when I run the task the annotations are
not recognized. .... That is, the annotation is there. I can read its type.
But if I ask the method for an annotation matching the class it doesn't
match. (Yes, the class matches the reported type.: e.g.,
com.foo.MyAnnotation.class)

So I think I have a classloader problem. My task accepts a path to find the
classes with the annotations. It creates a classloader from the ant project,
passing in the given path. My theory is that the classes loaded by my task
are on a different classloader than the MyAnnotation.class and that is why
they don't match. ... Sound right? .... If so how do I get them on the same
classloader?

Thanks in advance,
boz

Re: classloader problem?

Posted by Christofer Jennings <bo...@gmail.com>.
Ah ha! That was it! ... I was ...

   getProject().createClassLoader(classpath);

... when I needed to ...

   getProject().createClassLoader(MyAnnotation.class.getClassLoader();,
classpath);

THANKS Peter!

On Wed, May 7, 2008 at 8:49 AM, Peter Reilly <pe...@gmail.com>
wrote:

> Also remember to use the classloader that loaded the
> custom task as the parent for the new classloader
> created in the task.
>
> Peter
>
> On Wed, May 7, 2008 at 3:59 PM, Steve Loughran <st...@apache.org> wrote:
> >
> > Christofer Jennings wrote:
> >
> > > I think I have a classloader problem.
> > >
> > > I've made a custom task that looks through classes for a method
> > annotation,
> > > then makes a report. I've got junit tests that work in my IDE showing
> that
> > > the annotations can be found. But when I run the task the annotations
> are
> > > not recognized. .... That is, the annotation is there. I can read its
> > type.
> > > But if I ask the method for an annotation matching the class it
> doesn't
> > > match. (Yes, the class matches the reported type.: e.g.,
> > > com.foo.MyAnnotation.class)
> > >
> > > So I think I have a classloader problem. My task accepts a path to
> find
> > the
> > > classes with the annotations. It creates a classloader from the ant
> > project,
> > > passing in the given path. My theory is that the classes loaded by my
> task
> > > are on a different classloader than the MyAnnotation.class and that is
> why
> > > they don't match. ... Sound right? .... If so how do I get them on the
> > same
> > > classloader?
> > >
> > >
> >
> >  I think that hypothesis sounds right, but don't know where to deal with
> it.
> > Can you load the tags you want to look for in the classloader that you
> are
> > loading the classes in?
> >
> >
> >  ---------------------------------------------------------------------
> >  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: classloader problem?

Posted by Peter Reilly <pe...@gmail.com>.
Also remember to use the classloader that loaded the
custom task as the parent for the new classloader
created in the task.

Peter

On Wed, May 7, 2008 at 3:59 PM, Steve Loughran <st...@apache.org> wrote:
>
> Christofer Jennings wrote:
>
> > I think I have a classloader problem.
> >
> > I've made a custom task that looks through classes for a method
> annotation,
> > then makes a report. I've got junit tests that work in my IDE showing that
> > the annotations can be found. But when I run the task the annotations are
> > not recognized. .... That is, the annotation is there. I can read its
> type.
> > But if I ask the method for an annotation matching the class it doesn't
> > match. (Yes, the class matches the reported type.: e.g.,
> > com.foo.MyAnnotation.class)
> >
> > So I think I have a classloader problem. My task accepts a path to find
> the
> > classes with the annotations. It creates a classloader from the ant
> project,
> > passing in the given path. My theory is that the classes loaded by my task
> > are on a different classloader than the MyAnnotation.class and that is why
> > they don't match. ... Sound right? .... If so how do I get them on the
> same
> > classloader?
> >
> >
>
>  I think that hypothesis sounds right, but don't know where to deal with it.
> Can you load the tags you want to look for in the classloader that you are
> loading the classes in?
>
>
>  ---------------------------------------------------------------------
>  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: classloader problem?

Posted by Steve Loughran <st...@apache.org>.
Christofer Jennings wrote:
> I think I have a classloader problem.
> 
> I've made a custom task that looks through classes for a method annotation,
> then makes a report. I've got junit tests that work in my IDE showing that
> the annotations can be found. But when I run the task the annotations are
> not recognized. .... That is, the annotation is there. I can read its type.
> But if I ask the method for an annotation matching the class it doesn't
> match. (Yes, the class matches the reported type.: e.g.,
> com.foo.MyAnnotation.class)
> 
> So I think I have a classloader problem. My task accepts a path to find the
> classes with the annotations. It creates a classloader from the ant project,
> passing in the given path. My theory is that the classes loaded by my task
> are on a different classloader than the MyAnnotation.class and that is why
> they don't match. ... Sound right? .... If so how do I get them on the same
> classloader?
> 

I think that hypothesis sounds right, but don't know where to deal with 
it. Can you load the tags you want to look for in the classloader that 
you are loading the classes in?


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