Duplicate classes when using dependencies weave Maven AspectJ

We use the Maven AspectJ plugin to build our web application. It uses "weaveDependencies" to add aspects to some dependency jar files.

Now we end with two versions of some classes in the web application archive, one in WEB-INF/classes and one in the jar source file in WEB-INF/lib . It seems that only one of the classes has aspects.

I am afraid that this may cause problems.

What is the best way to fix this?

The same issue is discussed (without solution) on the Eclipse forums .


The whole pom.xml itself is huge, and of course, the included subprojects also have their own. I hope the excerpt from the WAR project is quite informative.

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors> <filters> <filter>${basedir}/src/etc/${environment}/environment.properties</filter> </filters> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.2</version> <!-- NB: do use 1.3 or 1.3.x due to MASPECTJ-90 - wait for 1.4 --> <dependencies> <!-- NB: You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${aspectj.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjtools</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> <configuration> <outxml>true</outxml> <aspectLibraries> <aspectLibrary> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </aspectLibrary> </aspectLibraries> <weaveDependencies> <weaveDependency> <groupId>OURPROJECT</groupId> <artifactId>OURPROJECT-api</artifactId> </weaveDependency> <weaveDependency> <groupId>OURPROJECT</groupId> <artifactId>OURPROJECT-service</artifactId> </weaveDependency> </weaveDependencies> <source>1.6</source> <target>1.6</target> </configuration> </plugin> 
+6
source share
1 answer

In the servlet container and inside the WAR, classes in WEB-INF / classes always take precedence over classes with the same name as inside jar in WEB-INF / lib.

This is a quote from the servlet specification :

The web application class loader must load the classes from WEB-INF / classes, and then from the JAR library to WEB-INF / lib.

This has been so since at least Servlet 2.4. This allows the application to selectively fix only a few library classes without repackaging the banks manually or through maven plugins.

In your case, you can be sure that classes with aspects will always be executed, as in WEB-INF / classes, and take precedence over classes in WEB-INF / lib.

+4
source

All Articles