Where to place proprietary configuration files


General J2EE: Where to place proprietary configuration files

  1. Hi and thanks for reading,

    Our J2EE system relies on a few .properties files to get configuration details. We need to be able to modify these files once the system is deployed, so they need to be visible at the EAR level.

    Currently, these files are located at the root of the common.jar file and therefore are not visible once deployed (unless we unzip the JAR, which we don't want). Where (in what directory) should we place these files? And how should we access these files in the code, in terms of relative paths?

    Thanks a lot!
  2. Just place them in your classpath and use java.util.ResourceBundle to read them in. You dont need to specify a path, but only a package name and file name just as if the proerties file were a class.

    example for a file named filename.properties in a package named com.guillaume:

    ResourceBundle props = ResourceBundle.getBundle("com.guillaume.filename"); //leave off the .properties

    String value = props.getString("key");

    Hope this helps
  3. Ok, looks interesting... In which classpath should I add my property file? Since the using class is in common.jar, I suppose I should set it in the common.jar manifest file, right? Unfortunately that does not seem to work...
    Thanks again,
  4. Ok, but we have a little more complicated situation in several ways:
    1. We are using XML files with our own format. There are a number of different formats for various purposes, each of which contains structured information.
    2. We have a large number of these files arranged in a directory hierarchy. This is done to allow inheritance and selective overriding of information from files in parent directories in the hierarchy.
    3. To allow multiple separately developed sub-packages all in the same EAR file, we want to allow multiple roots of these hierarchies. So, within an EAR file, there might be multiple JAR and WAR files, each of which has one of these config file hierarchy roots.

    Currently, we're not packaging the thing in WAR or EAR files, so we're just descending through the file system hierarchy. But I don't think this will work unless the server always unpacks the EAR/WAR into the file system. I'm playing with using getResources() to find the roots of the hierarchies, and that seems to work; but how would I descend down thru the hierarchies?