gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:30:16 24 4
gpt4 key购买 nike

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

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

恐怕这会引起问题。

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

同样的问题讨论(无解)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 中的类。

关于java - 使用 Maven AspectJ 编织依赖项时重复类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22123548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com