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

时间:2014-06-24 02:01:15

标签: sbt onejar sbt-onejar

我正在使用sbt和one-jar插件,但是当我运行已经创建的一个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)

我尝试将参数传递给jvm,如对one-jar remove verbose warning information on application load的一些回复中所建议的那样,但我仍然会收到恼人的警告。

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

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

1 个答案:

答案 0 :(得分:1)

tl; dr由于System.err来自JarClassLoader,因此没有简单关闭消息的方法。

我对插件知之甚少所以我解压缩了jar -xf src/main/resources/one-jar-boot-0.98.jar src/com/simontuffs/onejar/JarClassLoader.java 类,如下所示:

WARNING

在课堂上,在第998行,调用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

这促使我声称关闭它是不可能的(除非你可以关闭我不知道可能的整个{{1}}。)