Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » 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 11:34 Go to next message
Rudi Vankeirsbilck is currently offline Rudi Vankeirsbilck
Messages: 3
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 00:37 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 307
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 03:33 Go to previous messageGo to next message
Rudi Vankeirsbilck is currently offline Rudi Vankeirsbilck
Messages: 3
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 10:53 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 307
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 02:48 Go to previous messageGo to next message
Rudi Vankeirsbilck is currently offline Rudi Vankeirsbilck
Messages: 3
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 12:20 Go to previous message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 307
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.
Previous Topic:can't create class
Next Topic:A simple parametrized class question
Goto Forum:
  


Current Time: Tue May 28 04:46:28 EDT 2013

Powered by FUDForum. Page generated in 0.05671 seconds