I have written a J2EE application with EJBs and there is a helper class which this EJB extends. From that helper class I am trying to load a property file that is right there along with helper class files in the same folder. I used the following piece of code to get a handle to it but it fails with a NullPointerException.
java.util.Properties prop = new java.util.Properties();
prop.load(getClass().getResourceAsStream("xxx.properties"));
Can someone help me with this?
thanks in advance
Sheetal
-
Loading properties file within a J2EE application (4 messages)
- Posted by: sheetal P
- Posted on: May 02 2003 10:53 EDT
Threaded Messages (4)
- Re: Loading properties file within a J2EE application by Alan Choy on May 02 2003 12:59 EDT
- Loading properties file within a J2EE application by Anthony Randazzo on May 02 2003 19:14 EDT
- Loading properties file within a J2EE application by Steinar Overbeck Cook on May 04 2003 05:32 EDT
-
Re: Loading properties file within a J2EE application[ Go to top ]
- Posted by: Alan Choy
- Posted on: May 02 2003 12:59 EDT
- in response to sheetal P
You have to notice that EJB is running in the EJB container, which the detail implementation is various for different vendor. Hence, it is not good to put the properties file into the same directory as it may be out of context from the point of view of container.
I recommend you to use the full pathname then it should work fine. -
It worked[ Go to top ]
- Posted by: sheetal P
- Posted on: May 02 2003 17:44 EDT
- in response to Alan Choy
Thanks Alan, it worked when i used the complete path. i realize your point.
Sheetal -
Loading properties file within a J2EE application[ Go to top ]
- Posted by: Anthony Randazzo
- Posted on: May 02 2003 19:14 EDT
- in response to sheetal P
Sheetal,
Another approach would be to put the properties in the descriptor file and use JNDI to get your properties. This is more generic the hardcoding the path in your application.
Just a thought.
Good luck -
Loading properties file within a J2EE application[ Go to top ]
- Posted by: Steinar Overbeck Cook
- Posted on: May 04 2003 05:32 EDT
- in response to sheetal P
In order to make this truly portable and maintainable I would suggest:
a) Store the properties file in a well known location in the file system and declare the full path name in the JNDI ENC for the EJB we are discussing. Then you may use this full path name when loading the properties file.
b) Store the properties file inside your deployed .jar or .ear. Now you can reference the properties file by resource name as you indicated in your posting.