Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to deal with a property file and EJB

843830Apr 21 2008 — edited Apr 21 2008
Hello,
I'm quite new to the EJB technology.
My problem is, how to handle a property file?

Let's say I have a custom 'property.xml' (that holds some application specific constants) somewhere in my EJB jar or in a related jar (so it is in the classapth).
Usually (not with EJB) I would write a class (let's name it 'Props', see below) which reads the property file once and initialize some public static members.
In an object (see below 'MyClass') I would then use 'Props.memberName' if I want to have access to a constant property.

.
class with public static constants members; read the file only once; properties are in memory ...
public class Props
  public static String FOO = null;
  static
  {
    Properties props = new Properties();		
    try
    {
      props.loadFromXML(CConstants.class.getClass().getClassLoader().getResourceAsStream("propertyFile.xml"));
      FOO = props.getProperty("FOO");
    }
    catch(Exception e){...}
  }
}
The class that uses the properties<br>
public class MyClass
{
  ...
  public void doSomething()
  {
    ...
    String s = Props.FOO + " BAR";
    ...
  }
  ...
}
But unfortunately static things are not allowed in EJB ...

What is the preferred way to get access to the properties?
To read the file each time an EJB is used, will cause much disc-I/O and xml parsing (this is very unefficient).
Is there no mechanism to read such things once only?

I would be very pleased to get an answer, because I don't know how to solve this problem
Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 19 2008
Added on Apr 21 2008
1 comment
181 views