AspectJ LoadTimeWeaving on OSGI

698 views Asked by At

I'm trying to use aspectJ Load Time Weaving (no Spring) on OSGI with help of equinox jars (org.aspectj.runtime, org.aspectj.weaver, org.eclipse.equinox.weaving.aspectj on bundles folder and org.eclipse.equinox.weaving.hook located at the same folder as org.eclipse.osgi physical location) according to: https://wiki.eclipse.org/Equinox_Weaving_QuickStart

Here's the loading order of bundles:

[org.eclipse.equinox.weaving.hook::1 -> INSTALLED]
[org.aspectj.runtime::11 -> INSTALLED]
[org.aspectj.weaver::12 -> INSTALLED]
[org.eclipse.equinox.weaving.aspectj::13 -> INSTALLED]
[com.common-calculations_2.11::19 -> INSTALLED] //here I used aspects
[com.instrumentation_2.11::48 -> INSTALLED] //here I defined the aspects 
Done installing bundles
Starting bundles...
[org.eclipse.equinox.weaving.aspectj::13 -> ACTIVE]
[org.aspectj.runtime::11 -> ACTIVE]
[org.eclipse.osgi::0 -> ACTIVE]
 FRAGMENT Bundle - skip starting: org.eclipse.equinox.weaving.hook
 FRAGMENT Bundle - skip starting: org.aspectj.runtime
[org.aspectj.weaver::12 -> ACTIVE]
 FRAGMENT Bundle - skip starting: org.eclipse.equinox.weaving.aspectj
 Bundle started: [com.common-calculations_2.11::19 -> ACTIVE]
 Bundle started: [com.instrumentation_2.11::48 -> ACTIVE]

I want to know how should I start the hook jar? I'll appreciate any help... p.s. someone solved his issue by importing the bundle "org.eclipse.osgi" and the fragment "org.eclipse.equinox.weaving.hook" as "Binary Project with Linked Content" into his workspace, but I'm not really sure how to do that: https://www.eclipse.org/forums/index.php?t=msg&th=440862

Thanks for your replies

1

There are 1 answers

3
prenex On BEST ANSWER

Once I wrote a bigger article on this topic on my blog when I faced the issue at my job for a railroad traffic control application. It still runs with aspects at its core functionality - not just for call tracing, but for automatic resource and transaction handling for JPA and thread safety aspects and so on (so I know the solution still work in real life at my former project):

http://ballmerpeak.web.elte.hu/devblog/setting-up-aspect-oriented-programming-with-equinox-osgi-and-ajdt.html

Self-contained example code is provided at my github:

https://github.com/prenex/equinox_osgi_skeleton

I also add our email's content here if it might help others:

" Hi!

It was a bit time ago when I worked on the topic but surely it was working well for us and still is part of a plugin-based railroad traffic control application.

For your problem:

1.) Did you put the equinox.weaving.hook bundle near the core org.eclipse.osgi bundle? There were some not-so-clear stuff like this requirement the last time I worked on it that is why I wrote it down in a blog post. 2.) Did you try my example code from the following link?

https://github.com/prenex/equinox_osgi_skeleton

I would first try to run this example project of mine which already contains AspectJ in it and then compare your solution line-by-line at relevant places until it start to work.

Look at the following commit to see what I changed in a generic equinox+osgi skeleton project to add simple AspectJ support: https://github.com/prenex/equinox_osgi_skeleton/commit/882d7765f31a3fc8ee136e88b689fce116a73d1c

Best regards, Richard Thier

PS.: How did you stumble upon my blog? I am happy someone actually read it and find it helpful even if it does not completely solve all their problems. :-) "