Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hiding the logs from OneJar? #15

Open
fge opened this issue Apr 9, 2014 · 9 comments
Open

Hiding the logs from OneJar? #15

fge opened this issue Apr 9, 2014 · 9 comments

Comments

@fge
Copy link

fge commented Apr 9, 2014

Hello,

This plugin is what I was looking for for one of my projects (https://github.com/fge/json-schema-validator), so thanks for that!

I have one nitpick though. When I launch it, I see this output:

[Boot] INFO:  setProperties(com.simontuffs.onejar.JarClassLoader@7ecd2c3c)
[Boot] INFO:  using JarClassLoader: com.simontuffs.onejar.JarClassLoader
missing arguments
Syntax: java -jar jsonschema.jar [options] file [file...]
Options: 
--syntax: check the syntax of schema(s) given as argument(s)

After some digging around, I could find on StackOverflow that you could add this JVM option to silence this output (not documented on the one-jar project page!):

-Done-jar.silent=true

This works; however I'd like to avoid having users to type that each time!

Is there an undocumented option to gradle-one-jar allowing to generate a "silent jar" by default?

@rholder
Copy link
Owner

rholder commented Apr 10, 2014

It's actually an issue with the way one-jar-boot.jar initializes its custom logging in 0.97.1. That is indeed an annoying thing that I ran up against, too, using the latest version. You might get lucky with using the other version of one-jar-boot that I've packed into this plugin by setting useStable = false, as in:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    useStable = false
}

As I recall, the 0.97 version of one-jar-boot didn't seem to output the debug logging by default. You can manually add that version to your build by grabbing it from http://sourceforge.net/projects/one-jar/files/one-jar/one-jar-0.97/ and then pointing it to that custom jar with what's described here. If that works, I'll try to block out some time to include this older build back in the plugin.

I have come close to releasing my "quiet" version of one-jar-boot forked from the latest stable http://sourceforge.net/projects/one-jar/files/one-jar/one-jar-0.97.1/ branch so if the older version doesn't seem to work as well, let me know.

@fge
Copy link
Author

fge commented Apr 10, 2014

OK, so useStable=false brings out other messages which I cannot even silence with -Done-jar.silent=true:

fge@alustriel:~/src/perso/json-schema-validator$ java -Done-jar.silent=true -jar build/libs/jsonschema.jar 
myJarPath=file:/home/fge/src/perso/json-schema-validator/build/libs/jsonschema.jar
oneJarPath=file:/home/fge/src/perso/json-schema-validator/build/libs/jsonschema.jar
[ etc ]

As to http://sourceforge.net/projects/one-jar/files/one-jar/one-jar-0.97.1/, it redirects to 0.97 and I get the messages from the first attempt.

So, a failure so far. When you say you have "come close" to releasing a quiet version, what do you mean exactly? I could of course fork/modify (the SF issue even has a link to a patch that supposedly fixes that, haven't tested), but if duplicate work could be avoided...

@alexeyOnGitHub
Copy link

yep, same problem here. a ton of output from the fat jar created by this plugin.
e.g.

[JarClassLoader] WARN: org/mozilla/javascript/Token.class in lib/yuicompressor-2.4.6.jar is hidden by lib/js-1.6R7.jar (with different bytecode)
[JarClassLoader] WARN: org/mozilla/javascript/Parser$ParserException.class in lib/yuicompressor-2.4.6.jar is hidden by lib/js-1.6R7.jar (with different bytecode)
[JarClassLoader] WARN: org/mozilla/javascript/Parser.class in lib/yuicompressor-2.4.6.jar is hidden by lib/js-1.6R7.jar (with different bytecode)
[JarClassLoader] WARN: org/mozilla/javascript/Decompiler.class in lib/yuicompressor-2.4.6.jar is hidden by lib/js-1.6R7.jar (with different bytecode)
[JarClassLoader] WARN: org/mozilla/javascript/TokenStream.class in lib/yuicompressor-2.4.6.jar is hidden by lib/js-1.6R7.jar (with different bytecode)
[JarClassLoader] WARN: org/mozilla/javascript/Parser$1.class in lib/yuicompressor-2.4.6.jar is hidden by lib/js-1.6R7.jar (with different bytecode)
[JarClassLoader] INFO: LICENSE.txt in lib/zookeeper-3.4.5.jar is hidden by lib/hamcrest-core-1.3.jar (with different bytes)

etc

@LiberQuack
Copy link

Yup... disabling gradle-one-jar logs is essential... It should be disabled by default

@LiberQuack
Copy link

using useStable = false worked for me, just include it in your build.gradle and run your jar without any jvm parameter

it printed two lines of log with myJarPath=... and oneJarPath, but it's still acceptable

@gaffo
Copy link

gaffo commented Jun 4, 2016

Please fix this, I can't make a simple command line tool jar with the boot logging going on.

@chenrui333
Copy link

chenrui333 commented Feb 9, 2018

+1, the JarClassLoader log seems pretty huge.

@vektor330
Copy link

In case you haven't found this https://stackoverflow.com/a/13853353/992988:
one-jar.properties file with the single line one-jar.silent=true
does the trick for me.

@nros
Copy link

nros commented Jun 30, 2018

It seems, you have at least two options.

  1. set system property on command line

    java -Done-jar.silent=true -jar myAwsomeJar.jar
    
  2. use a custom class to wrap the boot class of one-jar.

    • create a custom boot wrapper and use package binlib (important!) because of this gradle plugin setting binLib
      package binlib;
      public class CustomBootWrapper {
          public static void main(final String[] args) throws Exception {
              // silence the logger of one-jar
              System.setProperty("one-jar.silent", "true");
      
              // load one-jar boot loader
              final Class<?> oneJarBoot = Class.forName("com.simontuffs.onejar.Boot");
              final Method bootMethod = oneJarBoot.getMethod("main", String[].class);
              bootMethod.invoke(null, (Object)args);
          }
      }
      
    • create your own manifest file
      Manifest-Version: 1.0
      Main-Class: binlib.CustomBootWrapper
      One-Jar-Main-Class: my.awesome.Main
      One-Jar-Show-Expand: false
      One-Jar-Confirm-Expand: false
      
    • tell the gradle plugin to use the custom manifest file and include the custom wrapper
      task myAwesomeJar(type: OneJar) {
          manifestFile = file('src/build/resources/META-INF/MANIFEST.MF')
          binLib = fileTree('build/classes/java/main/binlib')
          additionalDir = file('src/build/resources')
      }
      

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants