one-jar remove verbose warning information on application load

南楼画角 提交于 2019-12-12 08:22:06

问题


I am using Maven, with the one-jar pluggin, but when I run the one jar executable, I'm greeted with a wall of warnings, this is unacceptable for use

I've looked at every available resource on one-jar and see no instruction on how to keep the jar for spewing out tons of warnings when run, has anyone solved this?

JarClassLoader: Warning: META-INF/LICENSE.txt in lib/commons-io-1.4.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: META-INF/NOTICE.txt in lib/commons-io-1.4.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: META-INF/LICENSE.txt in lib/commons-lang-2.4.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: META-INF/NOTICE.txt in lib/commons-lang-2.4.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)

回答1:


I found that if you create a one-jar.properties file and put it in the root of your runtime classpath (ie, where your project .class files end up), it will be read by the one-jar Boot class. An entry in this properties file such as:

one-jar.silent=true

will suppress the one-jar log messages altogether.

Other values that the Boot class looks for are one-jar.info and one-jar.verbose.

The default level is INFO. As Pascal Thivent indicated above, you can also set a System property via the command line with the -D parameter of the java command, but if you do not want to have to stipulate or remember this, the properties file approach works great.




回答2:


It seems that these messages are printed when running in "verbose" mode. What I don't get is that the verbose mode doesn't seem to be activated by default.

Anyway, could you try to set the one-jar.verbose system property to false when running your one-jar:

java -Done-jar.verbose=false -jar <one-jar.jar>



回答3:


Regarding the latest-and-greatest One-Jar v0.97: The problem is there. The 'one-jar.properties' file actually needs to be put into the root of the final jar. It will, of course, have one line that reads, one-jar.silent=true. This can be done in Ant by setting something like <fileset dir="${build.dir}" includes="**/*.properties" /> inside the <one-jar ...> task.

It can also, just as easily, be placed into the command line using the java -Done-jar.silent=true -jar foo-jar-made-by-one-jar.jar command.

Nevertheless, it will still report a single line that it's loading properties from the One-Jar internal Boot class before going quiet. There is no way to get around this without changing source code starting at line 317 in Boot.java where the method initializeProperties logs the loading/merging operations. See Bug ID 3609329 at SourceForge in the One-Jar bug tracker where I provided the quick fix.

Summary: By adding the one-jar.properties file all but one line of extraneous logging is removed. This should help Maven users find a workaround.




回答4:


This is much better in the new version of the Maven one-jar plugin.

Add the plugin repository:

    <pluginRepository>
        <id>one-jar</id>
        <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
    </pluginRepository>

and use version 1.4.4 in the plugin definition.




回答5:


I found I needed to use version 1.4.5 (1.4.4 did not work) and then the suggestion to place a one-jar.properties file at the root of my jar file with a single line reading one-jar.silent=true worked for me.




回答6:


I upgraded fromr 1.4.3 to 1.4.4 as someone suggested before and that made the deal




回答7:


There's two places to get the one-jar plugin from.

  1. https://github.com/jolira/onejar-maven-plugin
  2. http://code.google.com/p/onejar-maven-plugin/

The 1st one claims to be just a copy of the 2nd one that's served from Maven's main repository. I was encouraged to use this one as it doesn't require specifiying an additional plugin repository that the 2nd one requires. However, when I switched to use the 2nd one (the official one), this problem went away for me.

Note - passing -Done-jar.verbose=false worked for me but not when set in file one-jar.properties as someone stated above.




回答8:


I submitted a patch for this quite some time ago that merely makes the default behavior silent.

    public static final int LOGLEVEL_VERBOSE = 5;

    // Loglevel for all loggers.
 -  private static int loglevel = LOGLEVEL_INFO;
 +  private static int loglevel = LOGLEVEL_NONE;

    private final String prefix;

AFAIK, it never got applied. Recently I fixed another issue, so I put my fixes out here:

https://github.com/nsoft/uno-jar

Please Re-read the "as is, no warranty" part of the license several times :)




回答9:


There is no way to do this without modifying the source code



来源:https://stackoverflow.com/questions/3662659/one-jar-remove-verbose-warning-information-on-application-load

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!