1

我将 sbt 与 one-jar 插件一起使用,但是当我运行已创建的 one-jar 可执行文件时,我会收到如下所示的连续消息流:

JarClassLoader: Warning: net/liftweb/json/Formats$$anon$4.class in lib/lift-json_2.9.2-2.5-M3.jar is hidden by lib/lift-json_2.9.1-2.4.jar (with different bytecode)
JarClassLoader: Warning: net/liftweb/json/JsonParser$BoolVal$.class in lib/lift-json_2.9.2-2.5-M3.jar is hidden by lib/lift-json_2.9.1-2.4.jar (with different bytecode)
JarClassLoader: Warning: net/liftweb/json/TypeInfo.class in lib/lift-json_2.9.2-2.5-M3.jar is hidden by lib/lift-json_2.9.1-2.4.jar (with different bytecode)
JarClassLoader: Warning: net/liftweb/json/Meta$$anonfun$mappingOf$1.class in lib/lift-json_2.9.2-2.5-M3.jar is hidden by lib/lift-json_2.9.1-2.4.jar (with different bytecode)

我尝试按照对one-jar remove verbose warning information on application load的一些响应中的建议将参数传递给 jvm ,但我继续收到烦人的警告。

使用 sbt-onejar 时如何关闭这些警告?

我正在使用最新版本的sbt-onejar

4

1 回答 1

1

tl;dr 没有简单的方法可以关闭这些消息,因为它们来自System.err.

我对插件知之甚少,所以我解压缩了这个JarClassLoader类,如下所示:

jar -xf src/main/resources/one-jar-boot-0.98.jar src/com/simontuffs/onejar/JarClassLoader.java

在类中,在第 998 行有对WARNING方法的调用:

if (!Arrays.equals(existing.bytes, bytes) && !name.startsWith("META-INF")) {
    // TODO: this really needs to be a warning, but there needs to be a way
    // to shut it down.  INFO it for now.  Ideally we need to provide a 
    // logging layer (like commons-logging) to allow logging to be delegated.
    if (name.endsWith(".class")) {
        // This is probably trouble.
        WARNING(existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with different bytecode)");
    } else {
        INFO(existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with different bytes)");
    }
} else {
    VERBOSE(existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with same bytecode)");
}

该方法WARNING实现如下:

protected void WARNING(String message) {
    System.err.println(PREFIX() + "Warning: " + NAME() + message); 
}

这让我声称关闭它是不可能的(除非你可以关闭整个System.err我不知道可能的)。

于 2014-06-24T20:07:37.723 回答