运行 jar 文件时增量设置类路径的问题

发布于 2024-10-01 02:13:24 字数 581 浏览 1 评论 0原文

我有一个包含在 A.JAR 中的应用程序。该 jar 有多个依赖项,因此它们在清单中指定为“lib/B.JAR lib/C.JAR lib/D.JAR”。我的安装目录中有 A.JAR,在它的下面有 lib 目录和其他三个目录。

我转到安装目录并运行“java -jar A.JAR”来运行该应用程序,它开始运行。但是,它会查找 log4j.properties 来设置 log4j。现在据我所知, log4j.properties 需要位于类路径中。

现在假设我想运行 A.JAR 的多个实例,但具有各种 log4j 属性。因此,我设置了 4 个安装目录(inst1、inst2、...),并在每个目录中放入了 A.JAR、自定义的 log4j.properties 和 lib 目录。

  1. 这是正确的方法吗(忘记复制本身,我可以使用符号链接来做到这一点)?也许有一种方法可以告诉 log4j 在运行时使用某些定义(-D)在特定位置查找属性?
  2. 如果我所描述的是一个很好的设置,那么我该如何实际运行它呢? Java 不会“捕获” log4j.properties 作为其类路径的一部分。运行“java -classpath . -jar A.JAR”也没有帮助。

I have an application contained in A.JAR. This jar has several dependencies so they are specified in the manifest as "lib/B.JAR lib/C.JAR lib/D.JAR". I have my installation directory with A.JAR, and under it I have the lib directory with the three others.

I go to my installation directory and run "java -jar A.JAR" to run the application, and it starts running. However, it looks for log4j.properties for setting up log4j. Now as far as I know, log4j.properties needs to be in the classpath.

Now let's suppose I want to run several instances of A.JAR, but with various log4j properties. So I setup 4 installation directories (inst1, inst2,...) and I've put A.JAR, a customized log4j.properties and the lib directory in each of them.

  1. Is this the right way to go (forget about the copying itself, I can do this with symlinks)? Maybe there's a way for telling log4j to look for the properties in a specific place using some define (-D) in runtime?
  2. If what I've described is a good setup, how can I actually run it? Java doesn't "catch" the log4j.properties as part of its classpath. running "java -classpath . -jar A.JAR" wasn't helpful as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残花月 2024-10-08 02:13:24

您可以使用 log4j.configuration 系统属性来定义您希望 log4j 使用的属性文件。

某个目录中的文件的一个简单示例是:

java -Dlog4j.configuration=file:/c:/foobar.properties YOUR CLASS PATH -jar JAR FILE

有关详细信息,请查看文档。特别检查默认初始化过程部分。

You can use the log4j.configuration system property to define the properties files you want log4j to use.

A simple example for a file in some directory would be:

java -Dlog4j.configuration=file:/c:/foobar.properties YOUR CLASS PATH -jar JAR FILE

For more information check the documentation. Especially check the Default Initialization Procedure section.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文