views:

30

answers:

1

Hi, I'd like to pass some parameters to a stateless session bean. I'd like to do something like I do when I configure a Servlet initial parameters in the web.xml file. Thanks

A: 

It is traditional to use a property file for this.

Jeanne Boyarsky
Ok, this is probably a stupid question, but how can I load the file from the EJB inside? If I white File f = new File("./file.properties"); it don't work, but I don't know how to access the context to retrive the real path. Can you help me?
s.susini
You use an "absolute" path. For example /config/file.properties. Also, note there is a Properties class that you should use instead of new File so it abstracts away the parsing.I should have mentioned that "env-entry" exists for the ejb-jar.xml. Most people don't use that because it is easier to have a property file vary across environments than the xml that is jar'd up within your ear.
Jeanne Boyarsky
@Jeanne: but wouldn't accessing the file system affect the portability of the app?
stratwine
@Stratwine: Not if it is deployed with the app. This isn't a random file on the file system. T his is a properties file deployed either in the ear or better yet to a directory that can be easily changed. But that's a rich topic and not something easy to discuss in comments.
Jeanne Boyarsky