4 Replies Latest reply on Jan 7, 2004 2:20 PM by twgerber

    Property file management

    twgerber Newbie

      I want to use an MBean to load java.util.Properties from an external file. I want objects in my application to talk to this MBean to get any properties they need. I do not want to include this file in my ear/war files - just as a standalone file so they get loaded and can be modified on the fly.

      In addition I want to be able to modify properties via the MBean and have the file updated so they are saved and to make these updated/new properties available to the application.

      Is there a standard MBean in JBoss I can use for this or do I need to write my own? Is there an example of this being done or has anyone done this?

      Does this even make sense to do?

      Thx

        • 1. Re: Property file management
          Andrew Boyd Novice

          Look in the properties-service.xml file in your deploy dir

           <mbean code="org.jboss.varia.property.SystemPropertiesService"
           name="jboss:type=Service,name=SystemProperties">
          


          You can then tell it to watch your properties file and it will watch for updates. I dont think it will change the file however from changing
          properties in the code.

          Andrew

          • 2. Re: Property file management
            twgerber Newbie

            I searched the docs and can't find out how to tell the mbean to monitor the files for chanages.

            Is there documentation on this?

            or can you tell me how to do that too?

            I appreciate the help.

            Tom

            • 3. Re: Property file management
              Andrew Boyd Novice

              Hey Tom,
              I stand corrected. I thought by telling the SystemProperties MBean
              what property files to load that it would also load changes. That was
              my main reason for using it.
              However, if you look in the JBoss source file:

              server\src\main\org\jboss\logging\Log4jService.java
              


              There is an inner class called :
               /**
               * A timer task to check when a URL changes (based on
               * last modified time) and reconfigure Log4j.
               */
               private class URLWatchTimerTask
              


              This class watches the log4j.xml file in the conf dir and reloads it when
              ever it changes.

              Using something similar you could write your own property handler or
              you could create a hack that would touch the properties-service.xml
              file because it uses the URLDeploymentScanner to see when it is modified
              and then re-reads the property files pointed to.

              Unless anyone else has a better suggestion I'll be doing something similar
              since that was a feature I was hoping for.

              Andrew

              • 4. Re: Property file management
                twgerber Newbie

                I know that through the console you can tell it to load a properties file - via the Load() method through the console.

                What I did is change the file, then put the URL/Name into the parameter for the mbean and it loaded the file right then.

                So you can have it reread a properties file by entering it just like it is in the xml file into the load() method.

                I would prefer a monitor like you mentioned - not sure if I'll have time to do it right now though so I may use this manual way for now.