Maven SLF4J:类路径包含多个SLF4J绑定
我在编译我的java代码时得到了Exception。请告诉我们如何解决这个冲突。
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-android-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-jcl-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-jdk14-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-nop-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-simple-1.7.7.jar!/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.AndroidLoggerFactory] Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException: Fatal error in constructor! ... 2 more
运行mvn dependency:tree
并搜索哪个依赖项具有您不想要的slf4j
实现,然后使用依赖项排除将它们排除在外:
org.someexternallib someexternallibartifact ... org.slf4j slf4j-log4j12 log4j log4j
看来你有几个SLF4J的实现; 你应该排除所有不必要的
此错误意味着您在类路径中有多个SLF4J实现。 查看错误具体说明的内容。 即: SLf4J: Found binding in.....
(这将打印它找到StaticLoggerBinder.class实例的所有jar文件)。 消除类路径中的所有这些jar,除了你需要StaticLoggerBinder.class实现的jar。
您可以转到POM.xml,打开Dependency Hierarchy并找到slf4j条目。除了通过右键单击“exclude maven artifact”排除其余条目
这个作品!! 更新porm.xml
org.someexternallib someexternallibartifact ... org.slf4j slf4j-log4j12 log4j log4j