我正在与Maven项目一起工作,并且有两个项目,ProjectA
并且ProjectB
。我ProjectA
是一个maven库,其pom如下所示:
ProjectA POM:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.texture.partial</groupId>
<artifactId>PartialPlatform</artifactId>
<version>2.1.5-RELEASE</version>
</parent>
<groupId>com.texture.transform.golden</groupId>
<artifactId>SampleClientProjectA</artifactId>
<version>1.0.4</version>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.texture.partial.core</groupId>
<artifactId>PartialKernel</artifactId>
</dependency>
<dependency>
<groupId>com.texture.webres</groupId>
<artifactId>WebResPartial</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.texture.kernel</groupId>
<artifactId>TextureServer</artifactId>
</dependency>
<dependency>
<groupId>com.texture.kernel</groupId>
<artifactId>Kernel</artifactId>
</dependency>
<dependency>
<groupId>com.texture.v3jars.Houston</groupId>
<artifactId>KerlDEL</artifactId>
</dependency>
<dependency>
<groupId>com.texture.kernel</groupId>
<artifactId>pKerl</artifactId>
</dependency>
<dependency>
<groupId>com.texture.kernel</groupId>
<artifactId>pKerlCore</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.cglib</artifactId>
</dependency>
<dependency>
<groupId>com.texture.partial.core</groupId>
<artifactId>ConfigWeb</artifactId>
</dependency>
<dependency>
<groupId>com.texture.partial.core</groupId>
<artifactId>PartialWeb</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:"${settings.localRepository}"/com/googlecode/jmockit/jmockit/1.7/jmockit-1.7.jar</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<instrumentation>
<excludes>
<exclude>**/test/**/*.class</exclude>
</excludes>
</instrumentation>
<formats>
<format>xml</format>
<format>html</format>
</formats>
</configuration>
</plugin>
</plugins>
</build>
</project>
在我上面的pom中,PartialKernel
带来了各种Spring Framework依赖项(如spring-core
,)的较旧版本spring-web
。它带来了3.2.8.RELEASE
版本,我想使用这两个spring框架的最新版本,即4.1.6.RELEASE
。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
我需要使用最新版本,因为某些类仅在最新版本中存在。因此,就像在ProjectA中一样,我在pom.xml中添加了这两个库的新版本。我有一个静态的void主代码,它将测试ProjectA
功能,并且工作正常,没有任何问题。
现在,我ProjectB
拥有与上述相同的pom,因为它没有最新版本的spring依赖项。在我的ProjectB
pom中,我具有的依赖关系ProjectA
和相同的代码,它们将测试的功能,ProjectA
但是每当我在其中运行相同的类ProjectB
时,总是会遇到此错误。
Exception in thread "main" java.lang.NoClassDefFoundError: org.springframework.util.concurrent.ListenableFutureCallback
Caused by: java.lang.ClassNotFoundException: org.springframework.util.concurrent.ListenableFutureCallback
我正在使用的所有与spring相关的最新代码都ProjectA
已经包含了spring的最新版本。我拥有的示例测试代码只是用来调用ProjectA
所有类来对其进行测试。
ProjectB POM:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.texture.partial</groupId>
<artifactId>PartialPlatform</artifactId>
<version>2.1.5-RELEASE</version>
</parent>
<groupId>com.texture.transform.golden</groupId>
<artifactId>SampleTestClientProjectB</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.texture.partial.core</groupId>
<artifactId>PartialKernel</artifactId>
</dependency>
<dependency>
<groupId>com.texture.webres</groupId>
<artifactId>WebResPartial</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.texture.kernel</groupId>
<artifactId>TextureServer</artifactId>
</dependency>
<dependency>
<groupId>com.texture.kernel</groupId>
<artifactId>Kernel</artifactId>
</dependency>
<dependency>
<groupId>com.texture.v3jars.Houston</groupId>
<artifactId>KerlDEL</artifactId>
</dependency>
<dependency>
<groupId>com.texture.kernel</groupId>
<artifactId>pKerl</artifactId>
</dependency>
<dependency>
<groupId>com.texture.kernel</groupId>
<artifactId>pKerlCore</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.cglib</artifactId>
</dependency>
<dependency>
<groupId>com.texture.partial.core</groupId>
<artifactId>ConfigWeb</artifactId>
</dependency>
<dependency>
<groupId>com.texture.partial.core</groupId>
<artifactId>PartialWeb</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.texture.transform.golden</groupId>
<artifactId>SampleClientProjectA</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:"${settings.localRepository}"/com/googlecode/jmockit/jmockit/1.7/jmockit-1.7.jar</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<instrumentation>
<excludes>
<exclude>**/test/**/*.class</exclude>
</excludes>
</instrumentation>
<formats>
<format>xml</format>
<format>html</format>
</formats>
</configuration>
</plugin>
</plugins>
</build>
</project>
但是,当我在ProjectB中添加spring依赖关系的最新版本时,我的测试代码开始正常运行。这就是我所不想要的。有什么办法让我的ProjectB自动开始使用我在ProjectA中使用的依赖项吗?如果他们想更改它,则可以在ProjectB中的代码中覆盖它。
您可以尝试从pom xml中排除依赖项。这是例子。
<dependency>
<groupId>com.texture.partial.core</groupId>
<artifactId>PartialKernel</artifactId>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句