开发者

Problem with incrementally setting up classpath when running a jar file

开发者 https://www.devze.com 2023-01-23 14:26 出处:网络
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

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 we开发者_JAVA技巧ll.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号