4 Replies Latest reply on Mar 15, 2007 9:32 AM by Pete Muir

    How to get Container properties

    knuwu Newbie

      I have the following problem:

      I like to store some of my application configuration parameters outside the ear-package. The reason for that is, that some configuration values will have different values for development, test and production enviroment.

      Best would be to store these values in a configuration file in the config directory of the container (equally to *-ds.xml configuration).

      First difficulty: Find out where the container is running and where to find the config directory.

      Second difficulty: If there are more than one application running on the same container, you have to chose a unique file name for your config file for each application running on that container. So the application must know it's name.

      Third difficulty: All above should even work, when you are testing your application with testng and you are running in an embedded ejb3 container.

      I found a solution for the first two problems. I get the deployment path from the Deploy Scanner MBean and calculate the path of the server config relative to that path. I derive the application name from the Init.instance().getJndiPattern() value.

      You may also get the path information from System.getProperty calls.

      But all is not working, if you start testing with the embedded ejb3 conatiner. The embedded ejb container does neither have the appropriate MBeans nor are there system properties.

      The only solution might be to set a special system property. Disadvantage of that solution: You have to make sure it will be set in all possible run configurations (testng plugin, testng ant call, jboss start with eclipse plugin, jboss start with command line).

      Is there a better solution?

        • 1. Re: How to get Container properties
          Pete Muir Master

          I use a different approach: Have seam-dev.properties, seam-prod.properties (etc.) and use my and script to copy the correct one to WEB-INF/classes/seam.properties when I do

          ant war
          - in fact, I think seam-gen should probably do this.

          • 3. Re: How to get Container properties
            knuwu Newbie

            Ok, perhaps I have to be more precise. The configuration properties I'm talking about do not belong to the seam configuration of components. I'm talking about application specific parameters controlling for examples the behaviour of business logic.

            Example: A booking application stores all canceled booking requests in an archive. Requests older than a given number of days will be delete. So you want to configure the amout of days different for your development, test and production enviroment. And of cause the system administrator should be able to change the value while the system is running.

            So it's not a good idea to store this kind of information to a configuration file inside your container. Otherwise you have to redeploy the application just for changing a value. On the other hand, this parameter is not changed often enough to justify storage in database with admin gui.

            • 4. Re: How to get Container properties
              Pete Muir Master

              I would argue that an application scoped seam component, with defaults set in seam.properties, and a quick crud, would be ideal for this. Certainly quick to develop - but changes would be lost between redeploys I guess.