英文:
Eclipse Maven: SLF4J: Class path contains multiple SLF4J bindings
问题
我在尝试运行Maven构建时遇到了这个错误。
有人能帮我解决一下绑定冲突问题吗?谢谢。
SLF4J: 类路径中包含多个SLF4J绑定。
SLF4J: 在 [jar:file:/Applications/Eclipse.app/Contents/Eclipse/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: 在 [file:/Applications/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class] 发现绑定。
SLF4J: 有关说明,请访问 http://www.slf4j.org/codes.html#multiple_bindings。
SLF4J: 实际绑定类型为 [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: 类路径中包含多个SLF4J绑定。
SLF4J: 在 [jar:file:/Applications/Eclipse.app/Contents/Eclipse/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: 在 [file:/Applications/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class] 发现绑定。
SLF4J: 有关说明,请访问 http://www.slf4j.org/codes.html#multiple_bindings。
SLF4J: 实际绑定类型为 [org.slf4j.impl.SimpleLoggerFactory]
英文:
I got this error when trying to run as Maven Build.
Could someone please help me resolve the binding conflicts, thanks.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Applications/Eclipse.app/Contents/Eclipse/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:/Applications/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:/Applications/Eclipse.app/Contents/Eclipse/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:/Applications/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]
答案1
得分: 19
这并不是 Eclipse 中的一个错误。我们只需要从“Maven integration for eclipse”中卸载 slf4j,这是已经安装在 Eclipse 上的附加软件。您可以在 Eclipse 市场中找到它。
按照以下步骤操作:
- 在 Eclipse 中,转到帮助 -> 点击市场 -> 点击已安装。在这里,您会看到已经安装了 Maven integration for eclipse。
- 现在点击更改按钮。在那里,您会看到 slf4j over logback 被选中。取消勾选它,然后点击确认按钮。这将从“Maven integration for eclipse”软件中卸载 slf4j。
现在您可以检查,在进行 Maven 构建时,是否消除了 slf4j 绑定错误。享受吧!
英文:
This is not a bug in eclipse. We just have to uninstall the slf4j from "Maven integration for eclipse" which is an additional software already installed on the eclipse. You can see this in eclipse market place.
Do the below steps:
- In eclipse, Go to help -> click on Market place -> click on installed. Here you will see the Maven integration for eclipse which is already installed.
- Now click on change button. There you will see slf4j over logback is checked. Uncheck it and click on confirm button. This will uninstall the slf4j from "Maven integration for eclipse" software.
Now you can check that the slf4j binding error is gone when you do the maven build. Enjoy!
答案2
得分: 7
这是 Eclipse 中已知的一个 bug。一个解决方法是,您单独安装 Maven(不使用 Eclipse 嵌入的 Maven 二进制文件)。
然后您可以在以下位置选择外部的 Maven 二进制文件:
Window->Preferences->Maven->Installations
我在这里使用的是 Windows,但在 Linux 中的操作步骤是相同的。从您的软件包管理器中安装 Maven(例如:sudo apt install maven),然后在 Eclipse 中激活它。
附注:在您的系统上安装了 Maven 后,命令 mvn dependency:tree
也会起作用。
英文:
This is a known bug in Eclipse. A workaround is, that you install Maven separately (not using the Eclipse-embedded Maven binary).
Then you can chose that external Maven binary under:
Window->Preferences->Maven->Installations
I'm using Windows here but in Linux it's the same procedure. Install maven from your package manager (e.g. sudo apt install maven), then activate it in Eclipse.
P.S: After you've installed Maven on your system, the command mvn dependency:tree
will also work.
答案3
得分: 5
这似乎是 Eclipse 版本 2020-09 及之前的一个 bug。我也遇到了这个问题。
参考:https://bugs.eclipse.org/bugs/show_bug.cgi?id=506676。
目前我所知道的没有解决方法。与项目的 Maven 依赖一起工作不会解决问题,因为这是由 m2e 插件和 Eclipse 引起的,所以超出了项目的范围,它在 IDE 内部。
英文:
This seems to be a bug in Eclipse up to version 2020-09. I got this as well.
Cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=506676.
No work around that I know of so far. Working with Maven dependencies of your project won't solve the problem since it is caused by the m2e plugin and eclipse, so it's beyond the scope of your project, it's inside the IDE.
答案4
得分: 1
我建议使用Maven依赖树插件。在项目的根目录,即您的pom.xml
文件所在的位置,运行以下命令:
mvn dependency:tree
您可以在输出中搜索/筛选slf4j
,以查看哪些库引入了slf4j
依赖以及引入了哪个版本。还可以通过命令行进一步限制输出,使用GAV坐标(Group, Artifact, Version)。然而,我通常发现查看整个依赖树很有用,至少可以确保我看到项目中的每个依赖关系。如果您能够完成到这一步,您已经完成了一半。
接下来的步骤是处理那些引入了不需要的slf4j
传递依赖的依赖项。您可以参考这个Stack Overflow的问题,从这些依赖项中_排除_slf4j
,在您的POM文件中可能会像这样:
<dependency>
<groupId>com.example</groupId>
<artifactId>foo-bar</artifactId>
<version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
您可能需要添加多个排除项,以删除除您真正想要包含的一个slf4j
依赖之外的所有依赖项。作为一种合理性检查,您可以再次运行依赖树命令,以验证构建中只有一个实现。
英文:
I would suggest using the Maven dependency tree plugin. Run the following from the root level of your project, where your pom.xml
file sits:
mvn dependency:tree
You may do a search/grep on the output for slf4j
to see which libraries are bringing in an slf4j
dependency, and what version(s) are being brought in. It is also possible to further restrict the output from the command line, using GAV coordinates. However, I often find it useful to see the entire tree, if for no other reason than I can be certain that I am seeing every dependency in my project. If you can get this far, you are about halfway done.
The next step is what to do about the dependencies which are bringing in the unwanted slf4j
transitive dependenc(ies). You may follow this Stack Overflow question and exclude slf4j
from these dependencies, using something looking like this in your POM file:
<dependency>
<groupId>com.example</groupId>
<artifactId>foo-bar</artifactId>
<version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
You may have to add multiple exclusions to remove all but the one slf4j
dependency you really want to include. As a sanity check, you may run depedency tree again, to verify that you only have one implementation in your build.
答案5
得分: 0
如果有任何问题导致,从命令行运行项目的Maven(即mvn clean package)。您将不会看到错误。正如Christoph Andriessens所说,这是在IDE中。
英文:
In case there is any question as the the cause, run maven from the command line for the project (i.e. mvn clean package). You will not see the error. As Christoph Andriessens said, it's in the IDE.
答案6
得分: 0
这个问题自2016年以来在Eclipse中已经被知晓:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=506676
在过去的五年里,没有任何变化。
英文:
This Bug is known in eclipse since 2016:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=506676
Nothing has changed for more than five years.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论