繁体   English   中英

ClassNotFound 与 Maven WAR 文件

[英]ClassNotFound With Maven WAR file

我环顾四周寻找解决方案,但可以找到任何合理的。 它们中的大多数都与 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.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:269) 处的 org/apache/commons/logging/LogFactory

它来自 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>

这也使用 commons-logging,范围为compile 但是这种依赖必须保持provided 不能改变!

可能导致冲突或其他问题的唯一其他依赖项是 activemq-core.jar,但我向其中添加了排除参数。 但仍然没有奏效。

任何帮助,将不胜感激! 谢谢!

Tomcat 类加载器将应用程序本地依赖视为最后( https://tomcat.apache.org/tomcat-8.5-doc/class-loader-howto.html )。

我最好的猜测是在 Tomcat 类路径中的某个地方已经有这个库(不同版本)(这并不奇怪,因为它是一个 Apache 日志库)。

您可以尝试将 commons-logging 定义为可选,它不会被传递导入,并将使用 Tomcat 中可用的内容(假设该版本与您的代码兼容)。 或者,您需要找到库并替换/升级它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM