Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Weaving into an OSGi bundle

LTW Weaving AspectJ in OSGi is a bit tricky
I had done it with a WAS ( OW2 JOnAS based on Felix) and it needs some JVM
parameters to work around the MANIFEST configuration. 
To allow the parent classloader to load the agent Aspectj and/or other
classes that are not bundlized, you have to set properties as described here


http://felix.apache.org/site/apache-felix-framework-configuration-properties
.html

The main properties are 
org.osgi.framework.bootdelegation
org.osgi.framework.bundle.parent

These operations are suitable for limited tests or monitoring, for a more
strong architecture, you have to bundle your aspects with MANIFEST files as
Martin said. 


Cordialement / Best regards

Jean-Louis Pasturel


-----Message d'origine-----
De : aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] De la part de Martin Lippert
Envoyé : vendredi 14 janvier 2011 12:03
À : aspectj-users@xxxxxxxxxxx
Objet : Re: [aspectj-users] Weaving into an OSGi bundle

Hi Tiago!

You can weave aspects into OSGi bundles at compile time, but you need to
take care of the dependencies that the weaving creates.

1.
The woven class will depend on types from org.aspectj.lang or
org.aspectj.runtime. So you need to change the OSGi manifest of your host
bundle to import those packages.

2.
The woven class will depend on the type of the aspect. So depending on where
the aspect actually is, you need to add that dependency to the OSGi manifest
as well. If you put your aspect into your host bundle, there is nothing you
need to do. If your aspect resides in a different bundle, you need to import
the package of the aspect into your host bundle via the manifest.

HTH,
Martin


On 14.01.11 11:52, Tiago Espinha wrote:
> Dear all,
>
> I've been trying to use AspectJ to weave an aspect into an existing OSGi
> bundle (I'm trying to weave directly in to the JAR, as that's actually
> the point of what I'm doing) but I'm getting strange results.
>
> So far I've been able to do the actual weaving but when I load the
> bundle onto Apache Felix, I get the following:
> -------------------8<---------------------
> g! felix:start 20
> g! Exception in thread "AWT-EventQueue-0"
> java.lang.NoClassDefFoundError: org/aspectj/lang/NoAspectBoundException
>          at
>
org.apache.felix.example.servicebased.host.DrawingFrame.<init>(DrawingFrame.
java:54)
>          at
>
org.apache.felix.example.servicebased.host.Activator$1.run(Activator.java:69
)
>          at java.awt.event.InvocationEvent.dispatch(Unknown Source)
>          at java.awt.EventQueue.dispatchEvent(Unknown Source)
>          at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
> Source)
> --------------------8<--------------------
>
> The bundle I've been using for my experiments is the one provided by the
> Felix project itself at [1]. I'm trying to weave the following aspect
> into the 'host' bundle:
> --------------------8<--------------------
> import java.awt.*;
> import java.awt.event.*;
> import java.util.*;
>
> import javax.swing.*;
>
> import org.apache.felix.example.servicebased.host.DrawingFrame;
>
> public aspect ComponentLogger {
> pointcut frameConstruction(DrawingFrame d) : this(d) &&
> execution(DrawingFrame.new());
>
>     before(DrawingFrame d) : frameConstruction(d)
>     {
>        JOptionPane.showMessageDialog(d,"We've just weaved into the
> constructor!");
>     }
> }
> --------------------8<------------------
>
> The goal of this would be to have a message dialog show up whenever a
> DrawingFrame is created. Am I doing something blatantly wrong? Or is it
> simply not possible to weave aspects into OSGi bundles?
>
> Many Thanks,
> Tiago
>
> [1] -
> http://felix.apache.org/site/apache-felix-application-demonstration.html
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



*********************************
This message and any attachments (the "message") are confidential and intended solely for the addressees. 
Any unauthorised use or dissemination is prohibited.
Messages are susceptible to alteration. 
France Telecom Group shall not be liable for the message if altered, changed or falsified.
If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
********************************



Back to the top