2011-07-14 59 views
1

我是Java EE初學者。我試圖修改一個系統(jboss-3.2.3,tomcat-5.0.28,struts-1.1)。當jboss/tomcat啓動時,我需要加載一個config.properties文件,因此,這些屬性可以用於整個應用程序。如何在服務器啓動時在jboss-tomcat-struts中加載config.properties文件

這就是我被要求做的事情:「第一次加載.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"> 
      ./conf/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> 

看起來像JBOSS加載正確:

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 

但是,當我嘗試空使用屬性收益:

String myProperty = System.getProperty("my.project.property"); 
System.out.println(myProperty); // null 

W帽子可能是錯的?

回答

0

看看JBoss System Properties Service。配置位於< jboss-home >/server/<服務器名稱> /deploy/properties-service.xml。這裏有一個例子:

<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> 
+0

謝謝,我會試試看。 – Luistar15

+0

我按照你的建議使用了properties-service.xml,但是有些失敗。任何想法? – Luistar15

+0

您可以發佈錯誤消息和/或堆棧跟蹤嗎? – Nicholas

相關問題