How to load config.properties file in jboss-tomcat-struts when server starts
I'm Java EE beginner. I'm trying to modify a system (jboss-3.2.3, tomcat-5.0.28, struts-1.1). I need to load a config.properties file when jboss/tomcat starts, so, the properties could be available for the entire application.
This is what I was asked to do: "Load the .properties the first time (only one time) so, when it need to be readed is already in memory".
How can I do that? Where can I start?
EDIT: I trying to load from properties-service.xml
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.varia.property.PropertyEditorManagerService" name="jboss:type=Service,name=PropertyEditorManager"></mbean>
<mbean code="org.jboss.varia.property.SystemPropertiesService" name="jboss:type=Service,name=SystemProperties">
<attribute name="URLList">
./c开发者_如何学运维onf/somelocal.properties
</attribute>
<attribute name="Properties">
my.project.property=This is the value of my property
my.project.anotherProperty=This is the value of my other property
</attribute>
</mbean>
</server>
Looks like JBOSS loads correctly:
2011-08-01 11:54:29,736 [INFO ] property.SystemPropertiesService - Loaded system properties from: file:/D:/jboss-3.2.3/server/default/conf/somelocal.properties
2011-08-01 11:54:29,736 [INFO ] property.PropertyEditorManagerService - Started jboss:type=Service,name=PropertyEditorManager
2011-08-01 11:54:29,736 [INFO ] property.SystemPropertiesService - Started jboss:type=Service,name=SystemProperties
But when I tried to use the property returns null:
String myProperty = System.getProperty("my.project.property");
System.out.println(myProperty); // null
What could be wrong?
Take a look at the JBoss System Properties Service. The configuration is in <jboss-home>/server/<server-name>/deploy/properties-service.xml. Here's an example:
<server>
<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss.util:type=Service,name=SystemProperties">
<!-- Load properties from each of the given comma seperated URLs -->
<attribute name="URLList">
http://somehost/some-location.properties,
./conf/somelocal.properties
</attribute>
<!-- Set propertuies using the properties file style. -->
<attribute name="Properties">
property1=This is the value of my property
property2=This is the value of my other property
</attribute>
</mbean>
</server>
精彩评论