Spark无法从fat-jar资源加载自定义log4j.properties

时间:2015-08-06 13:01:27

标签: apache-spark

我正在尝试新的和改进的火花1.4.1,但我经历了看起来像回归。

当spark-submit我的jar时,我传递指令来加载捆绑在我的fat-jar资源中的自定义log4j-light-redis.properties。在Spark 1.3.1中,这就像一个魅力。在1.4.1中,资源加载器找不到它:

log4j: Trying to find [log4j-light-redis.properties] using context classloader sun.misc.Launcher$AppClassLoader@4e25154f.
log4j: Trying to find [log4j-light-redis.properties] using sun.misc.Launcher$AppClassLoader@4e25154f class loader.
log4j: Trying to find [log4j-light-redis.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [log4j-light-redis.properties].

在spark 1.3.1中,它会正确找到资源:

log4j: Trying to find [log4j-light-redis.properties] using context classloader org.apache.spark.util.MutableURLClassLoader@1a1d6a08.
log4j: Using URL [jar:file:/E:/Projects/.../target/fatjar-1.1-SNAPSHOT-shaded.jar!/log4j-light-redis.properties] for automatic log4j configuration.
log4j: Reading configuration from URL jar:file:/E:/Projects/.../target/fatjar-1.1-SNAPSHOT-shaded.jar!/log4j-light-redis.properties
log4j: Parsing for [root] with value=[WARN,console,redis].

有人也有同样的问题,但火花邮件列表仍然没有承认这个问题:

http://apache-spark-user-list.1001560.n3.nabble.com/log4j-xml-bundled-in-jar-vs-log4-properties-in-spark-conf-tt23923.html

更新 看起来它的事件比我的想法更糟糕。我无法再从我的胖罐加载自定义log4j appender了!它失败并出现ClassNotFoundException!

1 个答案:

答案 0 :(得分:1)

在1.4.1中,在log4j初始化之前没有设置MutableURLClassLoader,就像它在1.3.1中一样。

以下是解释:

在解析SparkSubmit.scala中的参数时,它使用spark.util.Utils。这个对象通过ShutdownHookManager对log4j有一个新的静态依赖,它在从submit> gt调用setContextClassLoader(MutableURLClassLoader)之前触发它的初始化。 doRunMain> runMain

相关问题