使用 Maven AspectJ 编织依赖项时重复类



我们正在使用Maven AspectJ插件来构建我们的Web应用程序。它利用"weaveDependencies"向一些依赖jar文件添加方面。

现在我们最终在 Web 应用程序存档中得到了一些类的两个版本,一个在 WEB-INF/classes 中,一个在 WEB-INF/lib 的原始 jar 文件中。似乎只有classes中的那个才有这些方面。

恐怕这会引起问题。

解决此问题的最佳方法是什么?

同样的问题在Eclipse论坛上讨论(没有解决方案)。


整个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规范的引用:

Web 应用程序类装入器必须从 WEB-INF/装入类 首先是类目录,然后从库中的库 JAR 中 WEB-INF/lib 目录。

至少从 Servlet 2.4 开始就是这样。这允许应用程序有选择地只修补几个库类,而无需手动或通过 maven 插件重新打包 jar。

在您的情况下,您可以确定具有这些方面的类将始终被采用,因为它们在 WEB-INF/类中,并且优先于 WEB-INF/lib 中的类。

最新更新