I agree with Simone. There isn't a good way to effectively find out all
aspects using some classpath scanning mechanism. Note, however, that there
is an -outxml (or -outxmlfile <file>) option to 'ajc' that will create
aop.xml with an entry for all aspects.
-Ramnivas

2008/10/2 Simone Gianni <[EMAIL PROTECTED]>

> Hi Janos,
> unfortunately, at least AFAIK, there is no method in ClassLoader to find
> "all resources" in a package. The getResource (findResource,
> findResources etc..) only find resources if you already know the
> complete name of them (complete package). A number of tricks exists,
> like obtaining the path of the jar, then opening it as if it was a zip
> file, and scanning its content .. but they are not applicable in an
> "enterprise" like environment, where a hierarchy of classloaders may be
> in place and no direct access to jar files is possible (or even, there
> are no jar files at all). I also feel like this is a problem, but it's a
> ClassLoader problem in general, nothing AspectJ can easily fix.
>
> Anyway, exploring all possible classes for the presence of an annotation
> would be far too heavy. In even a simple web project there can be
> thousands of classes, scanning all of them so see which are aspects
> before even starting the "main" could require several seconds if not
> minutes.
>
> I can't think of any way to avoid the .xml file, maybe there is one, but
> without explicit support from the ClassLoader interface or some other
> java compiler internals (like a quick way to find all classes having a
> specific annotation, that would benefit quite a bit also JPA providers
> for example, which are also bound to XML based class listings in most
> cases) I think it's hard to do it in a reliable and standards compatible
> way. I don't think even a standard annotation processor could somehow
> ease this.
>
> Simone
>
> Háber János wrote:
> > Hmm!
> >
> > Tanks.
> >
> > " but have no idea that it exists an aspect"?
> >
> > Maybe a solution: Spring solve this probelm with a very simply way.
> > Get the selected package (maybe in aspectj possible using <include>
> > for this) and get all file-s and directories with
> > classloader.getResource method. And if the selected class is an
> > @Aspect... load it...
> >
> >
> > Janos
> >
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Simone Gianni
> > Sent: Thursday, October 02, 2008 3:17 PM
> > To: aspectj-users@eclipse.org
> > Subject: Re: [aspectj-users] LTW and annotations
> >
> > If I understand how LTW works correctly, the problem is in class
> > loading.
> >
> > Consider the situation where you have a bean with a doSomething
> > method,
> > and then have an advice that does something before that method.
> >
> > You application starts, it will load the bean with a new Bean(). At
> > this
> > point, the class loader loads the bean, but have no idea that it
> > exists
> > an aspect, so will not weave the bean. This is because, you never call
> > (and have explicitly no way) to call "new MyAspect()".
> >
> > In fact, if you had such a way of instantiating aspects, another
> > situation could arise and cause problems. Suppose you have also a
> > tracing aspect, that will intercept all calls to all methods. If this
> > tracing aspect gets loaded AFTER the bean has already been loaded, the
> > class loader is not able anymore to modify the bean, because it has
> > already been loaded.
> >
> > (in reality, there are some ways to do class redefining in recent
> > classloaders, but that brings another lot of problems)
> >
> > So, yes, you have to define your aspects in the aop.xml file. Since
> > this
> > is tedious, the ajc compiler can perform this task for you. If you are
> > using AJDT in Eclipse, there is an option for generating aop.xml on
> > the
> > fly under the AspectJ section of you settings. If you are compiling
> > from
> > command line using ajc, the -outxml option will generate it for you
> > (see
> > http://www.eclipse.org/aspectj/doc/released/devguide/ajc-ref.html ).
> > Also, the maven2 plugin for aspectj will generate the aop.xml file for
> > you.
> >
> > Hope this helps,
> > Simone
> >
> >
> >
> > Háber János wrote:
> >
> >> Hi!
> >>
> >> I have a question. I want to write an application. I using javaagent
> >> vm option to LTW. But in this case what needed in aop.xml (aop.xml
> >> required in this case if I not want to set any special weaving
> >> options?)
> >> If I only write:
> >> <aspectj>
> >>     <weaver options="-verbose -showWeaveInfo"/>
> >> </aspectj>
> >>
> >> I get: "no aspects registered. Disabling weaver for class loader..."
> >> WTF? I need to set the aspects both aop.xml and annotation in java
> >> file? Why?
> >> If Yes, why? The classloader can't detect the annotations?
> >>
> >>
> >> Janos Haber
> >>
> >> _______________________________________________
> >> aspectj-users mailing list
> >> aspectj-users@eclipse.org
> >> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >>
> >>
> >
> >
> >
>
>
> --
> Simone Gianni            CEO Semeru s.r.l.           Apache Committer
> MALE human being programming a computer   http://www.simonegianni.it/
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@eclipse.org
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to