【发布时间】:2020-05-01 21:43:10
【问题描述】:
我四处寻找解决方案,但可以找到任何合理的方法。它们中的大多数都与 JAR 有关。我不断收到这个令人沮丧的错误:
2020 年 1 月 15 日 11:36:06.605 严重 [Catalina-utility-1] org.apache.catalina.core.StandardContext.listenerStart 异常将上下文初始化事件发送到类 [org.springframework.web.context .ContextLoaderListener] java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory 在 org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:269)
它来自 commons-logging.jar (1.2)。
我已经添加了我的依赖,比如:
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
版本来自父pom.xml
我有这两个值得注意的插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<id>pal-copy-dependencies</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<inherited>false</inherited>
<configuration>
<excludeScope>provided</excludeScope>
<excludeClassifiers>shared</excludeClassifiers>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
<silent>true</silent>
<useBaseVersion>false</useBaseVersion>
</configuration>
</execution>
</executions>
</plugin>
和
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultEntries>true</addDefaultEntries>
<addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<classpathPrefix>WEB-INF/lib/</classpathPrefix>
</manifest>
</archive>
<attachClasses>true</attachClasses>
<classesClassifier>shared</classesClassifier>
<failOnMissingWebXml>true</failOnMissingWebXml>
<includeEmptyDirectories>true</includeEmptyDirectories>
<outputDirectory>${project.basedir}\lib</outputDirectory>
<webResources>
<webResource>
<directory>src/main/resources/ProcessOrderService</directory>
<include>*.*</include>
<targetPath>/ProcessOrderService/wsdl/</targetPath>
</webResource>
</webResources>
</configuration>
</plugin>
我不知道我做错了什么。更重要的是,当我将 commons-logging.jar 放在 Tomcat 的 lib 文件夹中时,它就像一个魅力。
我在这个 war 文件中有一个依赖项:
<dependency>
<groupId>com.test.mypackage</groupId>
<artifactId>common-files</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
这也使用公共日志记录,范围为compile。但是这种依赖必须保持provided。改变不了!
唯一可能导致冲突或其他问题的其他依赖项是 activemq-core.jar,但我添加了 excludes 参数。但是还是不行。
任何帮助将不胜感激!谢谢!
【问题讨论】:
-
我刚刚注意到
common-files和战争之间常见的任何依赖关系都会导致问题。
标签: java maven war maven-dependency