Thank you for your insight Jean-Louis. Just for future reference (in case
other users end up in the same situation), I just had to fix the imports.
Basically I had to edit the manifest file from the aspectjrt.jar as it has
two "faults":

1) It has a blank line between Manifest-Version: 1.0 and the rest of the
manifest's information. For some reason, Apache Felix ignores the rest of
the information if there's a blank line in the manifest file. (I'm not sure
whether this is expected behavior or if it's a bug in Apache Felix)

2) It does not export the two packages needed for weaving to work
(org.aspectj.lang and org.aspectj.runtime)

After fixing the manifest file of aspectjrt.jar and after adding those two
packages as imports in my weaved bundle, everything just works fine.

Maybe these tips will help other users in the future. In any case, thank you
very much for your help!

Cheers,
Tiago

On Fri, Jan 14, 2011 at 1:29 PM, <jeanlouis.pastu...@orange-ftgroup.com>wrote:

> 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-boun...@eclipse.org
> [mailto:aspectj-users-boun...@eclipse.org] De la part de Martin Lippert
> Envoyé : vendredi 14 janvier 2011 12:03
> À : aspectj-users@eclipse.org
> 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@eclipse.org
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@eclipse.org
> 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.
> ********************************
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@eclipse.org
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to