【问题标题】:Eclipse bug: SLF4J: Class path contains multiple SLF4J bindings [duplicate]Eclipse 错误:SLF4J:类路径包含多个 SLF4J 绑定 [重复]
【发布时间】:2021-05-23 09:28:45
【问题描述】:

安装后,我从 maven-archetype-quickstart 创建了项目并启动 dependency:tree 目标。这是 Eclipse 控制台中的输出:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/anahel/.p2/pool/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/Users/anahel/Documents/Apps/eclipse/ee/jee-2020-12/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/anahel/.p2/pool/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/Users/anahel/Documents/Apps/eclipse/ee/jee-2020-12/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[INFO] Scanning for projects...
[INFO] Downloading from : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.pom
[INFO] Downloaded from : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.pom (6.4 kB at 2.1 kB/s)
[INFO] Downloading from : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/25/maven-plugins-25.pom
[INFO] Downloaded from : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/25/maven-plugins-25.pom (9.6 kB at 14 kB/s)
[INFO] Downloading from : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-deploy-plugin/2.8.2/maven-deploy-plugin-2.8.2.pom
[INFO] Downloaded from : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-deploy-plugin/2.8.2/maven-deploy-plugin-2.8.2.pom (7.1 kB at 12 kB/s)
[INFO] Downloading from : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-site-plugin/3.7.1/maven-site-plugin-3.7.1.pom
[INFO] Downloaded from : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-site-plugin/3.7.1/maven-site-plugin-3.7.1.pom (19 kB at 31 kB/s)
[INFO] 
[INFO] -------------------------< me.anahel:deleteme >-------------------------
[INFO] Building deleteme 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ deleteme ---
[INFO] me.anahel:deleteme:jar:0.0.1-SNAPSHOT
[INFO] \- junit:junit:jar:4.11:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.330 s
[INFO] Finished at: 2021-02-21T01:59:50+10:00
[INFO] ------------------------------------------------------------------------

如何修复“SLF4J:类路径包含多个 SLF4J 绑定”。就我而言?

【问题讨论】:

  • @howlger 我该怎么办?在 Intellij IDEA 中没有这样的警告...
  • 忽略它和/或提供补丁。我在当前的 Eclipse 中没有看到这一点(在 Console 视图中?),因此提供 minimal reproducible example pom.xml 将是一个好的开始。
  • @howlger 最小可重现示例 - 在 maven-archetype-quickstart 上运行验证目标,如 Jave Enterprise Edition 2020-12 中的“Run As...”-“Maven build...”
  • 也在 面向 Java 开发人员的 Eclipse IDE 中?

标签: java eclipse maven


【解决方案1】:

首先,您需要找到包含这些“额外”包的违规包。您可以通过从 CLI mvn dependency:tree 运行以下 cmd 来执行此操作。这将输出依赖树。

一旦你知道哪个模块包含这些 SLF4J 包,只需像这样在你的 pom 配置中排除它们

<dependency>
    <groupId>package1</groupId>
    <artifactId>package1</artifactId>
    <version>${package1.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-id</artifactId>
        </exclusion>
        <exclusion>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

应该这样做:)

编辑:

在输出中您可以看到以下内容

SLF4J: Found binding in [jar:file:/Users/anahel/.p2/pool/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/Users/anahel/Documents/Apps/eclipse/ee/jee-2020-12/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]

因此,您的 .p2 池中有 1 个类用于 eclipse m2e 插件,而 eclipse/ee 目录中有另一个类。

【讨论】:

  • 我有问题地展示了dependency:tree 目标的输出。没有一个 SLF4J
  • 实际上它告诉你这两个绑定的确切位置
猜你喜欢
  • 2023-03-28
  • 2016-03-12
  • 2012-12-11
  • 2014-05-18
  • 2015-08-10
  • 1970-01-01
  • 2021-05-19
  • 2020-07-07
  • 2018-12-12
相关资源
最近更新 更多