scala - 如何避免 SLF4J 类路径中的多个类绑定
问题描述
我有一个使用 .jar 打包到 jar 中的 scala 代码sbt
。我把那个罐子放在下面$SPARK/jars
并试图使用我得到的类
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/tmp/hadoop-ubuntu/nm-local-dir/usercache/ubuntu/filecache/87/__spark_libs__5108127367259158326.zip/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/ubuntu/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
在阅读了关于 SO 的建议后,我在我的中添加了以下内容,build.sbt
以防止额外绑定slf4j
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % "1.7.7",
"org.slf4j" % "jcl-over-slf4j" % "1.7.7"
).map(_.force())
libraryDependencies ~= { _.map(_.exclude("org.slf4j", "slf4j-jdk14")) }
这没有解决问题,所以我尝试了另一种解决方案,我在这里找到了,并将以下内容添加到build.sbt
文件中
libraryDependencies ++= Seq(
//depencies
).map(_.exclude("org.slf4j", "*"))
//insert one without exclusion
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.1.3"
)
这不起作用并导致错误。
我检查了file:/tmp/hadoop-ubuntu/n...
位置,只有在我开始新的 spark 会话时才会创建它。我该如何解决这个问题?
解决方案
尝试Provided
:
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % "1.7.7" % Provided,
"org.slf4j" % "jcl-over-slf4j" % "1.7.7" % Provided
)
这应该排除他们。
也许你必须清除缓存/tmp/hadoop-ubuntu/nm-local-dir/usercache/ubuntu/filecache/
推荐阅读
- php - 从 PHP 运行 python 和显示 python 错误的更好方法
- ruby-on-rails - 在 api_only 模式下使用 Doorkeeper 和 Rails 时如何创建新应用程序?
- google-apps-script - 使用公式修改应用程序脚本数组项
- python - 我如何阻止这些乌龟错误,它们是什么意思?
- php - 点击事件打开新刀片页面 {{$data->title}}
- javascript - Promise 代码在reject() 错误处理之后和resolve() 之前停止执行
- r - 在作为光栅砖导入 R 之前,NetCDF 内坐标的平均变量值?
- spring-boot - Spring Boot - 控制器上的单元测试 - 404 答案
- x86 - 尝试在 Raspberry Pi 上的 x86 chroot 环境下运行 Wine 时出现总线错误
- android - Problem runing 'react-native run-android'