Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AspectJ » Circular dependencies(How to avoid circular dependencies in Eclipse when using AJDT?)
icon4.gif  Circular dependencies [message #1233201] Sat, 18 January 2014 23:21 Go to next message
Mark Boon is currently offline Mark BoonFriend
Messages: 6
Registered: January 2014
Junior Member
I'm doing an AspectJ project for work and ran into what seems a rather basic problem. I created a separate project for my aspects. In order to apply these aspects to existing projects, I convert those projects to AspectJ and I add my aspect project to the aspect-path of the existing projects. So far so good.

Now, in my aspects advice I need access to some of the data-types in the existing project(s). So I need to add a dependency to the project(s) with these data-classes to the class-path of my aspect project so that my aspects can use them. However, when adding the aspect project to the aspect-path of the existing projects, Eclipse automatically also added the aspect project as a project dependency (it says so at the bottom of the Aspect Build dialog.) So then I get lots of errors about a circular dependency in my projects. When I remove the project dependency, it also automatically removes it from the Aspect Build path.

I have worked around this problem by creating a separate project with some interfaces for the data-types. This is the only project that then is not an AspectJ project, so I can use it in my aspects. But it's an ugly workaround. And it prevents me using some of the nice AOP functionality of extending the data-types in my aspects to keep the original code clean.

This seems like such a basic problem that I must be missing something obvious. Can anyone enlighten me please?
Re: Circular dependencies [message #1233495 is a reply to message #1233201] Sun, 19 January 2014 20:46 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
The standard way of doing this is to add your target projects to your aspect projects' in path. This means that your aspect projects depend on your target project, but not the other way around. Your target projects do not need to be aspect projects.

There is a small complication here, though. This means that your target projects are first compiled using a regular java compiler, and then the byte code is passed to the aspect project and the aspects are woven in. You just need to be careful that when you produce your artifacts that you ship the woven byte code, not the original non-woven bytecode.

This is simple inside of Eclipse, but more tricky to set up build systems (like maven) with.

Let me know if you need more help getting started.

[Updated on: Sun, 19 January 2014 20:47]

Report message to a moderator

Re: Circular dependencies [message #1233864 is a reply to message #1233495] Mon, 20 January 2014 17:30 Go to previous messageGo to next message
Mark Boon is currently offline Mark BoonFriend
Messages: 6
Registered: January 2014
Junior Member
Can you explain how that would work in Eclipse? Because as I explained, when I add my aspects in the aspect-path of the target projects Eclipse automatically adds the aspect project to the target project path.

If the solution you propose is using load-time weaving, I haven't figured out yet how to set that up in Eclipse. Anyway, wouldn't that remove the Eclipse feature where it shows in the IDE where this advice is applied? As a beginner with AOP, that is quite a handy feature.

I believe in Maven it's actually simpler, as you can simply add the path to the aspect project to the ajc compile command without creating a project dependency.
Re: Circular dependencies [message #1233870 is a reply to message #1233864] Mon, 20 January 2014 17:51 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
In the situation that I am describing, you add the non-aspect (target) project to the inpath of the aspects project. The target project is added to the aspect project's build path, but not the other way around (ie- target project is oblivious to the aspects project). This way, there is no circular dependency. This is not load-time weaving.

The downside of this setup is that since the target project is oblivious, you will not see any gutter markers where the aspects are applied to the target project.
Re: Circular dependencies [message #1233946 is a reply to message #1233870] Mon, 20 January 2014 22:26 Go to previous messageGo to next message
Mark Boon is currently offline Mark BoonFriend
Messages: 6
Registered: January 2014
Junior Member
When I do as you describe, not only do the gutter markers no longer appear (not to mention the contents of the Cross Reference View) but also my aspects are no longer weaved in. Without the aspects in the build-path, how is ajc going to weave the aspects into the existing projects?
Re: Circular dependencies [message #1233949 is a reply to message #1233946] Mon, 20 January 2014 22:33 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
The aspects project will do the weaving of the target project. If you look at the bin folder of the aspects project, you will notice the class files of the target project mixed in there. These are the woven class files. You can specify a separate folder for the inpath class files, this is the inpath out folder, which you can set on the inpath page in your project settings. You can also specify an inpath jar.

When you run your project inside of Eclipse, you should not be adding the target project to the runtime classpath. Instead, just run your aspects project, which has all of the class files required for execution in it.
Re: Circular dependencies [message #1233956 is a reply to message #1233946] Mon, 20 January 2014 22:55 Go to previous messageGo to next message
Mark Boon is currently offline Mark BoonFriend
Messages: 6
Registered: January 2014
Junior Member
Suddenly I realized I may have misunderstood.Rather than adding all the existing projects to the aspect project's build-path, should I add it to the AspectJ in path?
Unfortunately, when I try that I get a few AspectJ Internal Compiler Error dialogs. Sad
Re: Circular dependencies [message #1233957 is a reply to message #1233956] Mon, 20 January 2014 22:59 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
Yes. You need to add to the inpath of the aspect project. The internal compiler error dialogs are unfortunate. Sad

What version of AJDT/AspectJ are you using? And what are the contents of the dialog?

Try also to do a full clean/build. See if you still see the errors.
Re: Circular dependencies [message #1233966 is a reply to message #1233956] Mon, 20 January 2014 23:34 Go to previous messageGo to next message
Mark Boon is currently offline Mark BoonFriend
Messages: 6
Registered: January 2014
Junior Member
OK, I commented out the pieces that the AspectJ compiler was choking on. Fortunately not pieces I needed to test this out. When I force a build on my aspect project it does display a dialog saying it's producing woven code. However, when executing the code it's clear none of my aspects are there.
Re: Circular dependencies [message #1233969 is a reply to message #1233966] Mon, 20 January 2014 23:42 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
It's worth raising an AspectJ bug and including the stack traces that you found. The bug may already be fixed if you are using an old version of AspectJ.

How are you executing the code? Are you executing directly from target project? Or are you executing the aspect project? If target project is on runtime classpath, make sure it appears below the aspect project. Remember, the aspect project contains all of the woven class files from the target project and so the aspect project should take precedence.
Re: Circular dependencies [message #1234400 is a reply to message #1233969] Tue, 21 January 2014 22:20 Go to previous message
Mark Boon is currently offline Mark BoonFriend
Messages: 6
Registered: January 2014
Junior Member
Strangely enough, after I updated my project from the source-control repository the error disappeared. I'm using Eclipse Kepler with AJDT 2.2.3 and AspectJ 1.7.3, which is the latest as far as I can tell.

I got the aspects to work, kind of, by adding the aspect project to the class-path and move it above the target projects. Now my aspects are being woven in and executed when I run the application. However, the output is quite different. Advice has been woven in at places where it wasn't before, most notably within the advice code itself despite a !within(<AspectClass>) clause to keep it out. And advice was left out at at least one place where it was woven in before. And quite straightforward at that, a fully qualified static function that clearly gets called but no aspect advice. And no more gutter icons to guide me...

Thanks for the pointers though, at least I learned a few useful things from your advice.
Previous Topic:Problem with Equinox Weaving in Virgo Tomcat
Next Topic:Aspectj and ClasCastException
Goto Forum:
  


Current Time: Fri Mar 29 05:03:59 GMT 2024

Powered by FUDForum. Page generated in 0.03495 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top