0 Replies Latest reply on Nov 22, 2002 4:18 PM by Andrzej Taramina

    jndi.properties workaround for external Tomcat

    Andrzej Taramina Newbie

      I've come up with a workaround to the problem that Tomcat servlets can't seem to find the jndi.properties file and thus connect to an external JBoss server.

      Hardcoding the properties works, but is ugly since then your code is tied to the specific location of the JBoss server.....and thus requries code changes and a recompile to deploy elsewhere.

      Michael's suggestion of putting the jndi info into the web.xml file would work, but has the disadvantage of being yet another detail that is not standard that deployers would have to look into.

      My workaround let's you put your jndi.properties file into /WEB-INF/classes as you would expect....and that's all you need do. The code is quite simple:

      Properties props = new Properties();

      props.load( servlet.getServletContext().getResourceAsStream("/WEB-INF/classes/jndi.properties" ) ); InitialContext

      ctx = new InitialContext( props );

      All it requires is that you have a reference to the servlet so you can do the getServletContext() call. That was a bit of a PITA for me...since the jmx-console code did not pass this into the class that needed the JNDI
      context...but that was pretty easily fixed.

      I still think it should read the jndi.properties file without this workaround...but this is a Tomcat issue and not a JBoss one, so I'll take it up on the Tomcat forums.