Search code examples
javaclassloaderjava-ee-6

java ResourceBundle.getBundle() undeterministic


I have a very, very strange situation happening on our Java EE app running on WebSphere.

EAR
  --someJar.jar
  ----config/propfile.properties

  --WAR
    ----WEB-INF
      ------classes
        --------config/propfile.properties

When the application start up, ResourceBundle.getBundle("config/propfile.properties") seems to read someProperty from the WAR/WEB-INF/classes/config/propfile.properties.

However, after the app is up and running, ResourceBundle.getBundle("config/propfile.properties") seems to read someProperty from someJar.jar/config/propfile.properties instead.

I think that's how it's happening is because we have different values for someProperty on each file, and we got some error (due to the incorrect value from the someJar.jar/config/propfile.properties). According to Java EE spec, WEB-INF/classes should get loaded first before anything else?

Is it even possible? We could not replicate the problem in any of our lower environments.

The WAR/META-INF/MANIFEST.MF is ...Class-Path: lib/begin...lib/end someJar.jar


Solution

  • If the second call to ResourceBundle.getBundle("config/propfile.properties") is from a class in the ejb module, it would no have access to WAR/WEB-INF/classes/config/propfile.properties. This is because each module has a different class loader.

    Download the ee spec at the following link (or the corresponding spec for your javaee standard).

    http://download.oracle.com/otndocs/jcp/javaee-6.0-fr-eval-oth-JSpec/

    In this version the relevant section is EE.8.3