如何在从一个jar可执行文件加载应用程序时关闭警告



我正在使用带有one-jar插件的sbt,但是当我运行已创建的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的几个响应中建议的那样向jvm传递参数,删除应用程序负载上的详细警告信息,但我继续得到令人讨厌的警告。

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

我使用的是最新版本的sbt-onejar.

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,我不知道这是可能的)。

最新更新