I have a project which uses compile time weaving of aspects. this project depends on another project, which is a included as a jar. I want to weave a class in the jar file while compiling. How can i achieve this.
Thanks
Compile-time weaving is the simplest approach. When you have the source code for an application, ajc will compile from source and produce woven class files as output. The invocation of the weaver is integral to the ajc compilation process. The aspects themselves may be in source or binary form.
An aspect weaver is a metaprogramming utility for aspect-oriented languages designed to take instructions specified by aspects (isolated representations of significant concepts in a program) and generate the final implementation code.
What AspectJ does is always pretty much the same: It modifies Java byte code by weaving aspect code into it. In case 1 you just get one set of class files directly from ajc . Case 2.1 creates additional, new class files. Case 2.2 just creates new byte code in memory directly in the JVM.
Post-compile weaving (also sometimes called binary weaving) is used to weave existing class files and JAR files. As with compile-time weaving, the aspects used for weaving may be in source or binary form, and may themselves be woven by aspects.
This jar needs to be added to the inpath of the project being compiled. The result will be a new set of class files. These new class files are the woven ones and should be used at runtime instead of the original jar.
How to set the in path is dependent on how you compile your code:
-inpath
option. See here http://www.eclipse.org/aspectj/doc/released/devguide/ajc-ref.html.The tricky part is to remember to avoid using the original jars in the running application, but rather the woven jars.
If you are using maven, you can use the aspectj-maven-plugin as well. It works well with eclipse (m2e).
In the plugin, just specify the groupId/artifactId of the dependent jar as well in the configuration/weaveDependencies/weaveDepedency.
See http://mojo.codehaus.org/aspectj-maven-plugin/weaveJars.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With