Accessing Properties file inside EJB


EJB design: Accessing Properties file inside EJB

  1. Accessing Properties file inside EJB (7 messages)

    I have a requirement for accessing and setting parameters from and to a properties file(complying with java.util.Properties), to customize my EJB logic.

      I have the following questions on this issue
    1. Can any one please give me solution for setting and getting the attributes and values from the properties file.
    2. what should be the structure of the properties file (example key and value pair for each of the attributes.??)

    Thanx in advance

    Threaded Messages (7)

  2. Using java.util.Properties you can write and read property file using store(OutputStream) & load(InputStream) method repectively. Default seperator for key value pair is ASCII = , : and whitespace character, which has to be in single line. Try it out with EJB through helper class since EJB use
    to restrict for direct accessing files or directories using package. I didn't try it out with EJB, give reply.
  3. I would use JNDI environment properties instead of a Properties file.

    Dave Wolf
    Internet Applications Division
  4. Probably I am wrong but isn't this environment properties file ( only to store the JNDI provider information? Could we store application specific properties in this file and JNDI will load them and bind the key-values pairs under the initial context?
  5. As of EJB 1.1 you can store any environment variables in the JNDI tree. These are mapped in the deployment descriptor. Think of them like normal property name/value pairs. You can then look them up via JNDI

    Boolean flag = (Boolean) ctx.lookup("java:comp/env/use_xa");

    Dave Wolf
    Internet Applications Division
  6. Accessing Properties file inside EJB[ Go to top ]

    Most servers allow you to have a startup class (Class that runs when the server starts) You could have the startup class loads up a properties file, and put the information into the JNDI tree. Then the EJB can lookup the initialisation information from there.

  7. Accessing Properties file inside EJB[ Go to top ]

     We evaluated several different options for this purpose. We found that the only portable mechanism that adheres to the spec is using the database to store the properties and bind them to JNDI the first time they are looked up (thanks to Ed Roman, who suggested this option).

    Options available include:
    1. load the properties file using container start up classes -- container specific (not that it is so bad but trying to get away from container specific code). In fact our code has negligible or no dependency on the container. Of course still needs lot of configuration per container but no code changes..

    2. load proeprties from a helper class - (i dont think this should even be a option) -- against the spec

    3. design a properties bean that would load up the properties from its environment and bind them to a new subcontext in JNDI ---- i think possible but not clean...

    4. using a database to store the properties and bind them to JNDI....

    my 2 cents...

  8. aaaaa