[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [aspectj-users] aspects that crosscut a mix of my code and classes in jars
- From: Wes Isberg <wes@xxxxxxxxxxxxxx>
- Date: Tue, 23 Dec 2003 11:22:30 -0800
- Delivered-to: email@example.com
- User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
Basically: weave and load the same aspect binaries once.
You can do that by including everything in one go:
ajc -sourceroots aspects/ -injars "lib.jar:app.jar" \
(this puts ALL classes into everything.jar, and it would
be an error to include lib.jar or app.jar in the classpath
along with everything.jar)
or by compiling the aspects and then weaving each:
ajc -sourceroots aspects -outjar aspects.jar
ajc -injar lib.jar -aspectpath aspects.jar -outjar lib-a.jar
ajc -injar app.jar -aspectpath aspects.jar -outjar app-a.jar
The benefit of this approach is that if your lib and app classes
are deployed to different places/classloaders, you can deploy
the aspect classes to a place/classloader visible to all.
That means you could use the same aspects for a number of apps
the same way you share libraries:
ajc -injar app2.jar -aspectpath aspects.jar -outjar app2-a.jar
ajc -injar app3.jar -aspectpath aspects.jar -outjar app3-a.jar
Here you could deploy aspects.jar to a shared/global classloader,
and each of the application jars to their respective places.
Conversely, I don't think you can have an aspected version of a
library in a global namespace/classloader apply to only one
application, and I suspect that if an unaspected variant of the
library is in a global namespace, putting the aspected version
in a local/app namespace won't work, unless the local classloader
expressly avoids the upwards delegation required of classloaders
(even in that case there might be interoperability issues).
P.S. - For more information on what code needs to be controlled by ajc
to implement a given join point, see the Programming Guide
"implementation" appendix. Since Erik made changes recently,
you might want the source for the latest from CVS:
You can also check out the docs (and lib) module and build the docs.
Mike Oliver wrote:
I am writing some aspects that crosscut classes that come from a
combination of my own classes that extend classes from other sources in
a Tomcat Web application and other classes in third party jars that
extend those same classes.
I am new to AspectJ but not new to Java or webapps, so I am looking more
for the proper approach, not specific help with the code.
For example is it better to have all the aspects in my code included in
the build of my classes/jars and to have all the aspects that crosscut
the classes in the third party jars in a separate build and output the
byteweaved classes into a separate jar?
If I have aspects that crosscut just a few of the classes in a third
party jar, do I need to have BOTH the third party jar and the new weaved
jar in the classpath, i.e. the WEB-INF/lib? Or does the weaved jar have
all the classes, both weaved and not weaved from the original -injars
and therefore should NOT be in the classpath?
aspectj-users mailing list