Has anyone tried successfully loading a ResourceBundle properties file from within a EJB? Any help appreciated. Thanks
It's very easy. Just make sure the bundle is in the EJB classloader's classpath.
If you're using ResourceBundle to contain properties for an EJB, I would recommend using the EJB's deployment descriptor (ejb-jar.xml) instead. The ejb-jar.xml file supports the <env-entry> element, which you can use to store name-value pairs that represent properties like this:
From your EJB bean class, you obtain the property like this:
InitialContext ic = new InitialContext();
String logDirectory = (String) ic.lookup("java:comp/env/logPath");
Hope it helps!
A EJB DD env entry can only be accessed by a single EJB. A resource bundle can be used by all EJB's and web app in the same .ear.
Hello Eric and SAF,
Thanks for you replies. I need to localize messages based on user locale. Hence the need for ResourceBundle. Have you tried the same with JBoss? Thanks
To explain further, my bundle.properties file is in the same place as Bean impl file. So I jarred them up. But the Server cannot seem to find it. Do I have to explicitly add it to class path? Thanks
If the property file is in your ejb jar file, then I dont see why you're ejb is having problems finding it.
Try placing the property file in your EAR root directory and reference the file from the ejb's Manifest file