问题描述
我有一个正在部署到WebSphere 7的Java EE 5 Web应用程序.
我希望我的log4j配置在ear文件外部,因此我可以在需要时调整日志内容而无需重建和重新启动EAR文件.
我的理解是我可以通过设置一个log4j.properties文件的位置 "系统变量"称为log4j.configuration. (例如log4j.configuration = c:/log4j.properties)
我的问题是,如何在WebSphere 7 Admin Console中设置此系统变量?
浏览我发现有Environment > WebSphere Variables,但这看起来不正确,因为那将为整个服务器设置一个变量.我猜想我想仅设置一个系统变量.
任何帮助或建议都非常感谢!
Rob
推荐答案
log4j.configuration属性是Java虚拟机系统属性.您可以通过将其添加到应用程序服务器的通用JVM参数列表的末尾来加载此属性.这是通过在WebSphere控制台中进行的,通过浏览以下内容:
Servers > Application servers > [app server name] > Process definition > Java Virtual Machine
在通用JVM参数下,添加以下内容:
-Dlog4j.configuration=file:C:/log4j.properties
单击此页面底部的Apply,并保存更改.这将需要重新启动应用程序服务器才能生效.
其他推荐答案
您也可以将共享库用于应用程序,然后将您的log4j.xml放在那里.
其他推荐答案
我找到了一个解决方案,可以分配给每个耳朵或战争外部log4j.xml配置文件:
- 我从我们的耳朵中提取了log4j.xml,将此孤独的XML缩成jar文件.将其放在服务器上,在WebSphere可访问的路径中,
- 创建一个共享库(WebSphere>环境>共享库)将类路径映射到此存档.确保选择"为此共享库使用隔离的类加载程序",否则您必须为应用程序的每个模块分配参考,而不仅仅是父元.
- 在我们耳边分配参考 (应用程序 - > ApplicationType-> WebSphere Enterprise Applications-> EAR名称 - >共享库参考 - >选择您的EAR->参考共享库 - >选择log4j配置jar)并添加.
- 重新启动应用程序
我使用这种方式将特定的外部log4j配置文件分配给每个呼吸的战争. 在这里您可以找到原始解决方案.
问题描述
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 needed without needing to rebuild and redeploy the EAR file.
My understanding is I can specify the location of my log4j.properties file by setting a "system variable" called log4j.configuration. (ex. log4j.configuration=c:/log4j.properties)
My question is, how do I set this system variable in the WebSphere 7 admin console?
Browsing around I see there is Environment > WebSphere Variables, but that doesn't look right because that would be setting a variable for the entire server. I'm guessing I want to set a system variable just for my application EAR file.
Any help or suggestions is greatly appreciated!
Rob
推荐答案
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.
其他推荐答案
You can also use shared library for an application and put your log4j.xml there.
其他推荐答案
I find a solution to assign to each EAR or WAR an external log4j.xml configuration file:
- 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,
- 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.
- 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.
- 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.