Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] aspects that crosscut a mix of my code and classes in jars

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" \
      -outjar everything.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.

<complication>
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).
</complication>

Wes

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:

http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/org.aspectj/modules/docs/progGuideDB/implementation.xml

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?

Ollie



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top