2 Replies Latest reply on Oct 10, 2008 2:51 PM by devireddy

    best way to read in properties ?

    devireddy

      HI

      I read in a book that using Java IO and directly reading in a properties file is not good in case of EJBs or any web application that is supposed to be portable. So, If I have to use classloader, which of the following is a better option.

      1. in = ClassLoader.getSystemResourceAsStream("properties.properties");

      2. in = this.getClass().getClassLoader().getSystemResourceAsStream("properties.properties");

      3. in = Thread.currentThread.getClass().getClassLoader().getSystemResourceAsStream("properties.properties");

      will these work if I have my properties file in the jar file that is deployed to server.

        • 1. Re: best way to read in properties ?
          peterj

          #3 is preferred, #2 usually also works (but do not ask me under what circumstances #3 would work but #2 would not), and #1 is to be avoided (it uses the master classloader, from what I recall, which will not get properties out of JARs embedded within EAR or WAR files).

          And yes, placing the properties file within a JAR within the EAR or WAR (or event at WEB-INF/classes within a WAR) is the best place for such files.

          • 2. Re: best way to read in properties ?
            devireddy

            Thq peter