General J2EE: Reading config files; are EAR files always unpacked to disk?

  1. I need to read XML config files from my application, and I'm wondering how to do it. They are in a hierarchy (files at deeper levels can override those in shallower levels). Now, if EAR files are always unpacked onto disk, then I can use file system type accesses. But if they're not (somehow read directly out of the EAR files or memory), then I'm not sure how to read them. getResourceAsStream will work for reading individual files, of course -- but I'm not sure how to read an entire hierarchy.

    Thanks in advance for any and all assistance.
  2. Generally speaking you shouldn't relay on ear unpacking. Thus, there are two options

    1. getResource is used and the application shuld know the hierarchy.

    2. A URL to a file system location of the config files provided to application as a paramter.

    Personally I favor the first one as it keeps the deployment singular while the second one adds one more deployment point (read maintainance headache).
  3. Urgh. Let's say the application does know the hierarchy. Can you get resources out of subdirectories, doing something like getResourceAsStream ("foo/bar.xml")?
  4. In rethinking this, knowing the file locations is not necessarily a problem. Now I'm back to the basic problem of how to access the config files in the first place. I tried putting them in the WAR file in the EAR, but my configuration reader code can't find the files. I do a "getResources" but it doesn't return the file(s) in the list: the only thing returned are files actually on the disk and pointed to by the application's CLASSPATH.