1 Reply Latest reply on Aug 29, 2002 12:26 PM by Péter Miklós

    Using jndi.properties file instead of hard coding

    naresh maharaj Newbie

      I have a servlet in Tomcat. The servlet does a look up as follows:

      Properties prop = new Properties();

      InitialContext initial = new InitialContext();
      Object objRef = initial.lookup("projectX/CountryRegionSession");

      now if i had to do this for hundreds of servlets it would be very repetative. Can anyone explain how i use a jndi.properties file to alleaviate this problem.
      I did create a jndi.properties file and place it in the classpath on the computer where the servlet is but this didn't work.


        • 1. Re: Using jndi.properties file instead of hard coding
          Péter Miklós Newbie

          I load jndi.properties manually like this:

          ClassLoader cl = Thread.currentThread().getContextClassLoader();

          Properties props = new Properties();

          InitialContext initial = new InitialContext(props);

          however, of course, it is also repetiative.

          You may place this code in a common class that all other classes can reach such as the ServiceLocator class in the j2ee petstore demo (java.sun.com).