3 Replies Latest reply on Feb 25, 2004 12:52 PM by nlmarco

    How to read *.properties files?

    nlmarco

      Hello *,

      maybe I'm wrong, but I've read some time ago, that you should not use java.io.* within EJBs. Thus, how can I read a configuration from a *.properties file?

      Is the following way really forbidden (even though it works)?

      public void ejbCreate() throws CreateException
      {
      try {
      Properties props = new Properties();
      props.load(MyBean.class.getResourceAsStream("MyBean.properties"));
      // ...
      }

      Thanks a lot in advance for your help!

      Best regards, Marco.

        • 1. Re: How to read *.properties files?
          julien.dubois

          Using java.io is forbidden because a filesystem is not considered a safe medium to use. You should use a database instead, for example.
          You could create a property table, with a PropertyEJB CMP bean, in which you will store your properties.

          Of course, you can still use java.io in a WAR (it is not forbidden in a WAR). That's what Struts do with its configuration file.

          • 2. Re: How to read *.properties files?
            cluck

            ...alternatively read in the properties to a singleton or some other application config object if Entity Beans are a non-starter (or you have no DB)

            • 3. Re: How to read *.properties files?
              nlmarco

              Hello!

              Thanks a lot for your replies! I'm using environment variables in my deployment descriptor, now. They have the disadvantage, that I cannot change them runtime within an EJB, but I think that I can live with that.

              But what is a "singleton" or "some other application config object"? Could you render that more precisely, please?

              Thanks a lot!

              Best regards, Marco :-)