how to set log4j.configuration system variable in WebSphere 7?

后端 未结 3 1479
囚心锁ツ
囚心锁ツ 2020-12-31 17:13

I have a Java EE 5 web app I\'m deploying to WebSphere 7 as an EAR file.

I want my log4j configuration to be external to the EAR file so I can tweak log content when

相关标签:
3条回答
  • 2020-12-31 17:54

    I find a solution to assign to each EAR or WAR an external log4j.xml configuration file:

    1. I extracted the log4j.xml from our EAR, Zipped this lone XML into a JAR file. Placed it on the server in a path accessible by WebSphere,
    2. Create a Shared Library (WebSphere > Environment > Shared Libraries) mapping the classpath to this archive. Make sure to select "Use an isolated class loader for this shared library" or you'd have to assign reference for each module of your application rather than just the parent EAR.
    3. Assigning the reference within our EAR (Application -> ApplicationType -> WebSphere enterprise applications -> EAR NAME -> Shared library references -> SELECT YOUR EAR -> Reference shared libraries -> SELECT THE LOG4J CONFIGURATION JAR) and ADD IT.
    4. Restart the application

    I used this way to assign a specific external log4j configuration file to each WAR in an an EAR. Here you can find the original solution.

    0 讨论(0)
  • 2020-12-31 18:06

    The log4j.configuration property is a Java Virtual Machine system property. You can load this property by adding it to the end of your application server's list of generic JVM arguments. This is done in the WebSphere Console by navigating through the following:

    Servers > Application servers > [app server name] > Process definition > Java Virtual Machine

    Under Generic JVM arguments, add the following:

    -Dlog4j.configuration=file:C:/log4j.properties

    Click Apply at the bottom of this page, and save your changes. This will require a restart of the application server to take effect.

    0 讨论(0)
  • 2020-12-31 18:08

    You can also use shared library for an application and put your log4j.xml there.

    0 讨论(0)
提交回复
热议问题