如何指定用于 Java webstart 应用程序的 logback 配置? [英] How do I specify a logback configuration for use in a Java webstart application?

查看:32
本文介绍了如何指定用于 Java webstart 应用程序的 logback 配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向许多内部 Java webstart 应用程序添加日志记录,最好使用 logback 日志记录框架和 logback.groovy 配置文件.我希望在 webstart 应用程序 .jnlp 文件中指定这一点,但不清楚如何做到这一点.

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.

我尝试在我的主 jar 的资源中添加 logback.groovy 文件(即包含我的 main 方法的那个),但没有被 logback 接收.

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.

我也尝试了各种尝试将 logback.groovy 文件添加到 <resources> 部分的 .jnlp 文件:

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>

值得注意的是,logback 期望在类路径上引用配置文件作为它所在的文件夹,而不是文件本身 - 请参阅 常见问题解答.

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.

但是,我真的不确定这将如何应用于 Java Webstart.

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

这可能吗?如果是这样,我该怎么做?

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

推荐答案

所以...我最终为此使用的方法是(与 Askel 的评论一致)将 logback.groovy 配置文件放入 /src/main/resources.

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.

然而,我们以多种不同的方式使用我们的 Java 库,我不想在默认情况下将 logback 配置文件包含在 jar 中.部分原因是我们有多个库,并且 logback 不能很好地处理多个配置文件.同样根据版本,我想使用不同的 logback 配置.

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.

对于我们的 webstart 版本,我们使用 webstart-maven-plugin 来构建库、组装依赖项等.但是在进行构建之前,我们复制 logback.groovy 配置文件到 /src/main/resources - 这包括该库的构建文件.然后,在构建/发布之后,,您可以从 /src/main/resources 中删除配置文件.

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.

然而,这个插件也将运行 mvn install,这会将库和 logback 配置文件放在你本地的 maven 仓库中.因此,在删除构建/发布/临时配置后,我们再执行一次mvn clean install,这将覆盖该库.

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.

这篇关于如何指定用于 Java webstart 应用程序的 logback 配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆