【问题标题】:Maven with dependency on "logback-classic" still gives "java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory" exception依赖于“logback-classic”的 Maven 仍然给出“java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory”异常
【发布时间】:2016-09-17 20:11:44
【问题描述】:

我有一个 Maven 项目,在 pom.xml 文件中有以下依赖项:

<dependencies>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.7</version>
    </dependency>
</dependencies>

但是我仍然收到“java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory”异常。

我也试过添加

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.20</version>
</dependency>
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>1.7.20</version>
</dependency>

但它们没有任何区别。

我该如何解决这个问题?

【问题讨论】:

  • 我尝试添加“slf4j-api”和“slf4j-log4j12”,但这并没有改变任何东西。这些不应该是自动添加的吗?
  • 我也曾经添加logback-core,但这不应该是您问题的答案/原因
  • 检查你的依赖 jars,看看它们是否有那个类......你可以通过mvn dependency:copy-dependencies 做到这一点,然后像jar -tf target/dependency/my-jar-name.jar 一样破解每个依赖jar ...

标签: java maven


【解决方案1】:

尝试添加这个:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>

更新 这对我来说很好。您确定您的 pom.xml 中没有任何重复或版本问题吗?

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.2</version>
        </dependency>

更新2

顺便说一下,我还排除了 spring 定义中的 commons-logging。

【讨论】:

  • 这没有帮助。我还更新了我原来的问题。还是谢谢!
  • 嗯,太奇怪了。我正试图让我的论文项目在 IntelliJ 之外构建(它确实有效)。你能试试吗? github.com/circle-packing/best-fit
  • 我猜你应该排除 commons-logging.. 但我将它排除在 spring 依赖项之外,看起来你不使用 spring..
  • 我将&lt;exclude org="commons-logging"/&gt; 添加到我的依赖项中,但现在我收到一个错误,提示“排除”是一个无法识别的标签。
  • 添加:commons-loggingcommons-logging
猜你喜欢
  • 2016-04-20
  • 1970-01-01
  • 2017-09-04
  • 1970-01-01
  • 2017-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-30
相关资源
最近更新 更多