How do I specify a logback configuration for use in a Java webstart application?
Asked Answered
C

1

1

I want to add logging to a number of internal Java webstart applications, preferably using the logback logging framework and logback.groovy configuration files. I expect to specify this in the webstart application .jnlp file, but it's not clear how to do this.

I have tried adding the logback.groovy file in the resources of my main jar (i.e. that which contains my main method), but that didn't get picked up by logback.

I have also tried various attempts to add the logback.groovy file to the <resources> section of the .jnlp file:

<jnlp ...>
  <resources>
    <j2se version="$j2seVersion" />
    $dependencies // from maven-webstart-plugin

    // some reference to my logback configuration - e.g. 
    <dir href="log/" />
  </resources>
</jnlp>

It's worth noting that logback expects the configuration files to be referenced on the classpath as the folder in which it resides, not to the file itself - see FAQs.

However, I'm really not sure how this would apply to Java Webstart.

Is this possible? If so, how do I do this?

Cluny answered 28/7, 2014 at 18:0 Comment(4)
assuming you use maven, have you tried to put the logback.groovy in src/main/java ?Watchband
@Askel - it's not clear to me what you're suggesting. As indicated in the question, I had tried putting the logback.groovy file in src/main/resources. Why would I put it in src/main/java? What does that have to do with using maven? (Which I am, as the question indicates.)Cluny
afaik using logback in webstart app or normal java app should be the same. You just need to make sure the config files get picked up from the classpath. I didnt add anything in the jnlp files to make logback work. Simply made sure the config file was part of the .jar package.Watchband
what i had to fix was in maven config make sure it included the right files when building the jar. maven.apache.org/plugins/maven-resources-plugin/examples/…Watchband
C
0

So... the approach that I ended up using for this was (in line with Askel's comments) to put the logback.groovy configuration file into /src/main/resources.

However, we use our Java libraries in a number of different ways, and I didn't want to include the logback configuration file in the jar by default. In part, this is because we have several libraries, and logback doesn't play nicely with multiple configuration files. Also depending on the release, I wanted to use different logback configurations.

For our webstart releases, we use the webstart-maven-plugin to build the library, assemble the dependencies etc. But before doing this build, we copy the logback.groovy configuration file to /src/main/resources - this includes the file in the build for that library. Then, after the build/release, you can remove the configuration file from /src/main/resources.

However, this plugin will also run mvn install, which will put the library with the logback configuration file in your local maven repository. Therefore, after the build/release/temp configuration removal, we do another mvn clean install, which will overwrite that library.

Cluny answered 28/9, 2015 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.