0

I recently started using AspectJ LTW. I use Eclipse with the AJDT. I basically use the "outjar" option to create my "AspectJ Library (.jar file)" with the compiled .aj files.

Next step is to use this jar file within a "normal" Eclipse Java project which just works perfect if I have the aspectjweaver.jar library on the javaagent path:

-javaagent:lib/aspectjweaver.jar

My next goal is to use a second aop.xml file within this "normal" java project. Even this works good if the META-INF/aop.xml file is located on the class loader search path. Now I discovered this:

http://www.eclipse.org/aspectj/doc/released/README-1612.html

(scroll down to "More flexible pointcut/code wiring in aop.xml")

The following XML specification works without problems:

<aspectj>
 <aspects>
  <concrete-aspect name="MyAspect">
   <before pointcut="set(* *.myStringField) AND args(message)"
       invokeClass="my.package.SomeRegularJavaClass" invokeMethod="someMethod(JoinPoint tjp, java.lang.String message)" />
  </concrete-aspect>
 </aspects>
</aspectj>

But what I'm actually interested in, is to "pass" my own argument/variable/message to the method someMethod. Something like:

<aspectj>
 <aspects>
  <concrete-aspect name="MyAspect">
   <before pointcut="set(* *.myStringField) AND args(message)"
       invokeClass="my.package.SomeRegularJavaClass" invokeMethod="someMethod(JoinPoint tjp, java.lang.String message, java.lang.String "customMessage")" />
  </concrete-aspect>
 </aspects>
</aspectj>

So is there a way to pass a string (for example) to the method someMethod? Or are there any other options available?

Domi
  • 1,451
  • 2
  • 13
  • 25
  • I'm a little unsure what you are trying to do. When will "customMessage" be resolved? Will this variable be resolved when your app is launched? Or will the variable be different each time the pointcut is invoked? – Andrew Eisenberg Mar 13 '12 at 16:01
  • Its just a string. So no, it will not be different each time. – Domi Mar 13 '12 at 17:19
  • @AndrewEisenberg On the README I also found this: "notice that in the case above which does argument binding, the names are bound according to the XML specification, not according to the parameter names in the Java code." I guess its not possible to pass my own paramter/method-argument then. – Domi May 14 '12 at 20:48

0 Answers0