Hey!

AspectJ typically creates one weaver per class loader. When trying to configure 
load-time weaving it asks that class loader for aop.xml resources that are 
visible (via a getResources() call on the class loader)

So you can put them anywhere that might be seen via that lookup, it will be 
looking for a META-INF/aop.xml or META-INF/aop-ajc.xml .  If you want to 
sidestep this process and instead provide a direct location you can set the 
property 
-Dorg.aspectj.weaver.loadtime.configuration=file:/path_to_aop_xml_file;file:/path_to_another_aop_xml_file

They don’t override each other, instead they are all loaded and considered to 
be a definition of the system.

AOP XML is for:
- listing the affects you want to be in effect
- possibly defining a subset of types the weaver might see that you want to 
weave (limit it to a particular package or something)
- set options on the weaver to control behaviour
- concretize aspects.  Typically done if your aspect is abstract and has no 
concrete point cut, you provide the point cut in the aop.xml:
    <!-- define a concrete aspect inline -->
    <concrete-aspect name="com.xyz.tracing.MyTracing"
      extends="tracing.AbstractTracing"
      precedence="com.xyz.first, *">
      <pointcut name="tracingScope" expression="within(org.maw.*)"/>
    </concrete-aspect>

There are a few things in readmes that haven’t made it into the docs…

Aspect Scoping: https://www.eclipse.org/aspectj/doc/released/README-169.html
When defining an aspect in aop.xml you can specify the types it should apply to 
- useful if the original aspect had a wider scope than you want it to apply to 
in this instance.

Declaring aspects completely in aop.xml: 
https://www.eclipse.org/aspectj/doc/released/README-1612.html
You can also fully define an aspect these days in aop.xml, so if you have a 
plain POJO (no aspectj syntax, no aspectj annotations) then you can define the 
point cut and the method in the pojo that should act as the advice. 
<concrete-aspect name="MyAspect">
  <before pointcut="execution(* Hello.say2(..)) AND args(message)"
   invokeClass="SomeRegularJavaClass" 
   invokeMethod="someMethod(JoinPoint tjp, java.lang.String message)"/>
  <after pointcut="execution(* Hello.say2(..)) AND args(message)"
   invokeClass="SomeRegularJavaClass" 
   invokeMethod="someOtherMethod(JoinPoint tjp, java.lang.String message)"/>
</concrete-aspect>

So, following on from that:

        • Is it possible to set other parameters from aop.xml and send values 
to aspect. I mean as runtime values?

You can specify pointcuts but not really other things. You should use a 
different mechanism for that (spring property placeholders?) - maybe it depends 
what you want to set.

        • Can the aop.xml reside in the META-INF folder on the java app? Will 
it override if I have a default one in the same directory but in lib?

Can be anywhere under an META-INF that the class loader will see when that 
getResources() call is made.

        • I want to be able to set a directory path where all data from 
"Pointcut" will be stored. Is it possible to set it at runtime ( not using a 
system property)?

Not quite sure what you mean on this one? Perhaps you mean having an aop.xml 
that defines all your concrete pointcuts and pointing at that explicitly? You 
can do that with the property above ( 
-Dorg.aspectj.weaver.loadtime.configuration)

        • Do I only need the following for compiling the app:

I think you mean when running the app as we are load-time weaving - yes if the 
config is all already captured in aop.xml files all you need is the aspects on 
the class path and to start the JVM with the weaver jar.

Cheers
Andy

> On Nov 6, 2018, at 5:12 AM, Mikael Petterson <mikaelpetter...@hotmail.com> 
> wrote:
> 
> Hi Andy,
> 
> Thanks for your really good support.
> I realized that I might need to use LTW for using my library (containing the 
> aspects) with different java apps.
> The reason for it is that we need an easy way to enable/disable aspect as 
> well as only use a subset of them.
> 
> Therefore I have a couple of questions:
> 
> Is it possible to set other parameters from aop.xml and send values to 
> aspect. I mean as runtime values?
> Can the aop.xml reside in the META-INF folder on the java app? Will it 
> override if I have a default one in the same directory but in lib?
> I want to be able to set a directory path where all data from "Pointcut" will 
> be stored. Is it possible to set it at runtime ( not using a system property)?
> Do I only need the following for compiling the app:
>  <configuration>
>                     <argLine>-Xms512m -Xmx2048m</argLine>
>                     <!--  AOP: Load-Time Weaving  -->
>                     
> <argLine>-javaagent:"${settings.localRepository}"/org/aspectj/
>                         aspectjweaver/${aspectj.version}/
>                         aspectjweaver-${aspectj.version}.jar
>                     </argLine>
>                     <useSystemClassLoader>true</useSystemClassLoader>
>                     <forkMode>always</forkMode>
>       </configuration>
> 
> and of course a dependency to the library containing  the aspects?
> Your advice is greatly appreciated.
> 
> br,
> 
> //mikael
> 
> 
> 
>  
>  
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@eclipse.org <mailto:aspectj-users@eclipse.org>
> To change your delivery options, retrieve your password, or unsubscribe from 
> this list, visit
> https://www.eclipse.org/mailman/listinfo/aspectj-users 
> <https://www.eclipse.org/mailman/listinfo/aspectj-users>
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://www.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to