我们正在使用Maven AspectJ插件来构建我们的Web应用程序.它利用“weaveDependencies”为某些依赖jar文件添加方面.
现在我们最终在Web应用程序归档中有两个版本的类,一个在WEB-INF / classes中,另一个在WEB-INF / lib中的原始jar文件中.似乎只有班级中的一个具有这些方面.
我担心这会引起问题.
解决这个问题的最佳方法是什么?
讨论了相同的问题(没有解决方案)over at the Eclipse forums.
整个pom.xml本身是巨大的,当然包含的子项目也有它们自己的.我希望WAR项目下面的摘录足够丰富.
<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>
解决方法
在servlet容器和WAR内部,WEB-INF / classes中的类总是优先于在WEB-INF / lib中的jar内找到完全相同名称的类.
这是servlet spec的引用:
The Web application class loader must load classes from the WEB-INF/
classes directory first,and then from library JARs in the
WEB-INF/lib directory.
至少从Servlet 2.4开始就是如此.这允许应用程序有选择地只修补几个库类,而无需手动或通过maven插件重新打包jar.
在您的情况下,您可以确定将始终使用具有方面的类,因为它们位于WEB-INF / classes中,并且优先于WEB-INF / lib中的类.