Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AspectJ » Duplicate classes when using maven weave dependencies(Duplicate classes when using maven weave dependencies)
Duplicate classes when using maven weave dependencies [message #1050023] Fri, 26 April 2013 15:34 Go to next message
Rudi Vankeirsbilck is currently offline Rudi VankeirsbilckFriend
Messages: 5
Registered: April 2013
Junior Member
My project consists of a number of modules, say module A and B and classes from module A have advice defined in aspects from module B. The advice is call, execution and inter type advice. I quickly found that I can add <weaveDependencies> in my pom file to get this working.

This has been working for quite some time now and we have started to look at assembling the project into a working set of deployable components. We discovered that the weave dependencies have a side effect that the classes from module A that have execution and inter type advice in module B are actually recompiled in the target directory of module B. so A/target/classes contains SomeClass.class and B/target/classes also contains a SomeClass.class. The first is the original compiled class, the latter is the one that has the advice.
When simply bundling all the JARs together and constructing a classpath from that, we find at runtime two different versions of SomeClass and depending on the order of the class path it will sometimes be the one that contains the advice and sometimes the one without the advice.
The problem is even worse when SomeClass implement an interface SomeInterface. In that case, SomeInterface is also duplicated in B's target directory. The same applies to exception classes that on the method signatures of SomeInterface or SomeClass.

I was wondering how this problem is typically tackled? How do I safely remove all duplicates from the constructed JARs or is it recommended to hardcode the classpath order such that B.jar is always before A.jar and therefore the VM will always load the classes with the advice?
Re: Duplicate classes when using maven weave dependencies [message #1050386 is a reply to message #1050023] Sat, 27 April 2013 04:37 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
There are two ways that you can set up inter-project compile time weaving. By placing the project to weave on the aspect path or on the in path.

If you go into Help -> Help Contents -> AspectJ Devlopement User Guide -> Tasks -> Using a multiproject setup, you can read about how to configure your projects. If this doesn't answer your question, let me know.
Re: Duplicate classes when using maven weave dependencies [message #1051751 is a reply to message #1050386] Mon, 29 April 2013 07:33 Go to previous messageGo to next message
Rudi Vankeirsbilck is currently offline Rudi VankeirsbilckFriend
Messages: 5
Registered: April 2013
Junior Member
Frankly, I am having a problem finding the resources that you are pointing out to me. When you say "go into Help -> ..." do you mean on the http://www.eclipse.org/aspectj website?

I have googled the development user guide for could only find "'Development Environment guide" but that focusses mainly on ant-like environments.
I have read the documentation of the codehaus' aspectj-maven-plugin again and than demonstrates the setup I have (i.e. with weaveDependencies). Moreover, the options weaveDependencies and weaveDirectories all seem to produce output in the target directory:

weaveDependencies
List of of modules to weave (into target directory). Corresponds to ajc
-inpath option (or -injars for pre-1.2 (which is not supported)).

weaveDirectories
List of of directories with .class files to weave (into target directory).
Corresponds to ajc -inpath option.
Re: Duplicate classes when using maven weave dependencies [message #1052045 is a reply to message #1051751] Mon, 29 April 2013 14:53 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
No, I mean the help menu in Eclipse. Since you have AJDT installed, you should see an entry for the "AspectJ Developement User Guide". If you don't, then you don't have AJDT installed and you must install it. Go to http://eclipse.org/ajdt/

And if you are using maven, make sure to also install m2e and the AJDT configurator for m2e (that is maven integration for eclipse and AJDT integration for m2e respectively). Also, you should be using the aspectLibraries option: http://mojo.codehaus.org/aspectj-maven-plugin/libraryJars.html
Re: Duplicate classes when using maven weave dependencies [message #1052498 is a reply to message #1052045] Tue, 30 April 2013 06:48 Go to previous messageGo to next message
Rudi Vankeirsbilck is currently offline Rudi VankeirsbilckFriend
Messages: 5
Registered: April 2013
Junior Member
That explains a lot, I am not using AJDT, in fact I am not using eclipse at all but using IntelliJ with its maven integration.

Maybe you can explain what ajc options I should be setting for my module B (that is weaving classes from module A) to avoid that the ajc compiler recompiles the classes from module A in the output directory of module B. With that I should be able to configure the aspectj-maven-plugin I think.
Re: Duplicate classes when using maven weave dependencies [message #1052839 is a reply to message #1052498] Tue, 30 April 2013 16:20 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
OK. You posted to the AJDT forum, so I made the assumption that you were using AJDT and Eclipse. You need to compile your project A with ajc and add project B to its aspect path. That is the only way that you can avoid duplication. In the aspectj-maven-plugin, the option to use is aspectLibraries.
Re: Duplicate classes when using maven weave dependencies [message #1061690 is a reply to message #1052839] Mon, 03 June 2013 13:55 Go to previous messageGo to next message
Rudi Vankeirsbilck is currently offline Rudi VankeirsbilckFriend
Messages: 5
Registered: April 2013
Junior Member
Finally got round to try this today. Having read the documentation, the aspectLibraries maven plugin option relies on the aspectPath option on the ajc compiler and that says that compiled aspects in JARs on the aspectPath will be applied to the sources that are about to be compiled. The docs also explicitly say that the JARs on the aspectLibraries need to be defined as dependencies in the pom.

However, the problem is have is that the pom that contains my aspects is say module B and that depends on module A but its the classes in module A that need the weaving. That creates a circular dependency doesn't it.

Any other way that I can tackle this?
Re: Duplicate classes when using maven weave dependencies [message #1061722 is a reply to message #1061690] Mon, 03 June 2013 15:07 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
Then, you should be using the weaveDependency option. See this example: http://mojo.codehaus.org/aspectj-maven-plugin/weaveJars.html This is equivalent to the inpath option of the ajc command.
Re: Duplicate classes when using maven weave dependencies [message #1061724 is a reply to message #1061722] Mon, 03 June 2013 15:10 Go to previous messageGo to next message
Rudi Vankeirsbilck is currently offline Rudi VankeirsbilckFriend
Messages: 5
Registered: April 2013
Junior Member
That's what I was using right at the start. I have pom B that contains my aspects with weaveDependency for pom A. That however, produces duplicate .class files. Say that pom A has a class Example and that pom B has an aspect with advice on class Example. The weaveDependency option copies the Example class from pom A and weaves the aspects in the target directory of pom B.
When I then put all JARs of my pom on the classpath, I have the Example class twice on the class path, the original version and the woven version.
I would like to get rid of this duplication without having to write ant scripts that unpack/pack JARs and reassembles them.

Many thanks for all your efforts,

Rudi.
Re: Duplicate classes when using maven weave dependencies [message #1061735 is a reply to message #1061724] Mon, 03 June 2013 16:30 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
According to the docs, the weaveDependency should work. I am not overly familiar with the aspectj-maven-plugin, so there may be something I am missing, or there maybe a bug in the plugin. If you paste the relevant portion of your pom, I can take a look at it, but you'd probably get a better response on the mailing list. http://mojo.codehaus.org/aspectj-maven-plugin/mail-lists.html
Re: Duplicate classes when using maven weave dependencies [message #1062686 is a reply to message #1051751] Mon, 10 June 2013 11:36 Go to previous message
David Mark is currently offline David MarkFriend
Messages: 1
Registered: June 2013
Junior Member
now this is something great..
Previous Topic:Debugging LTW weaved classes
Next Topic:How to display command line of an application that does not start?
Goto Forum:
  


Current Time: Thu Apr 18 23:59:46 GMT 2024

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

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

Back to the top