How to get Atlassian's Spring OSGI bundle to import aspectj bundle?

Ryan Rich August 2, 2011

Hi,

We have some pre-existing code that makes use of AOP via spring and aspectj, but when I try to get this code to run as an osgi plugin I cannot get the aspectj bundle to be imported by the Spring bundle that Atlassian ships with the framework which results in classloader errors like the following:

java.lang.ClassNotFoundException: org.aspectj.lang.reflect.AjTypeSystem

I have taken an osgified aspectj bundle from the spring ebr repository and installed it as a bundle and it shows up fine in the felix web console. If I add an Import-Package instruction to my plugin it correctly imports the aspectj library. I just can't get the spring bundle to import it which is necessary since Spring is ultimately generating the proxy objects via the aspects I have defined. Is there a trick for including OSGI bundles so the plugin framework libraries can import them and the classloaders will be happy?

Thanks,

Ryan

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Don Brown [Atlassian]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2012

Bundles are loaded by the plugin system in the following "runlevels":

  1. Framework bundles including Spring and some plugin glue code
  2. Bundle plugins
  3. User-installed plugins

Therefore, if you wanted Spring to bind to another bundle, it'd have to be in the framework bundle "runlevel" (I put that in quotes as OSGi does have a runlevel concept, but this isn't technically it).

If this is a plugin just for your instance, you could cutomize the bundles in the framework bundles runlevel by pulling the zip out of the atlassian-plugins-osgi.jar, modifying it to include aspectj, then copying it into WEB-INF/classes so it gets picked up before the one in the plugin framework jar. If this is a plugin you want to be a drop in and installable from PAC, you'll have to raise a feature request in the plugin framework to get aspectj included.

Ryan Rich January 31, 2012

Thanks Don, I appreciate the info on the workaround to get this working. I also opened a request at https://studio.atlassian.com/browse/PLUG-851 for you guys to start including this as a framework bundle, hopefully you guys will give it some consideration.

Tobias Löbermann February 24, 2016

Hi @Don Brown [Atlassian]

I have the same problem and followed your instruction. I copied/extracted the osgi-framework-bundles.zip from atlassian-plugins.osgi-3.2.5.jar from JIRA/atlassian-jira/WEB-INF/lib and include the aspactjrt.jar in this zip. The modified osgi-framework-bundles.zip is now placed in my JIRA/atlassian-jira/WEB-INF/classes folder. 

But when I try to install my plugin which include a Spring-Customer.xml in WEB-INF/spring/ (in my plugin jar). I always get the NoClassDefFound exception. It seems that the aspectjrt.jar is not loaded. I am using JIRA 6.3.13 in the moment. 

NoClassDefFoundError: org/aspectj/lang/reflect/AjTypeSystem

Do I have to include the aspectjrt-1.8.8.jar into another zip or jar? 

Hope you can help me with this, thanks a lot.

 

Regards
Tobias

0 votes
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2011

None that I know of. Latest OSGI implementations should care about -Dorg.osgi.framework.system.packages env variable, but I do not think Atlassian is using the latest version.

Take it with a grain of salt: I may be wrong, since I didn't have much time to dig into it.

Check this article: http://blog.springsource.com/2009/01/19/exposing-the-boot-classpath-in-osgi/, it may give you clues...

Don Brown [Atlassian]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2012

The version of felix we use does support that, but iirc we block it as it would completely overwrite the one that we need to get the system running. I believe the one to try is atlassian.org.osgi.framework.system.packages, but again, I'd recommend against it.

TAGS
AUG Leaders

Atlassian Community Events