3 Replies Latest reply on Jun 25, 2003 8:36 PM by Adrian Brock

    Binding to JNDI

    Scott Parmley Newbie

      Hello everyone!

      I have a fairly simple question. I am writting an n-tier application for a client. The client wants to have access to a configuration file that resides outside of the .ear. I have found a good place to put the properties file, but now, I want to load that file into JNDI so that my beans can use it. My solution has been to create a servlet that is essentially an init object. I want that servlet to create a Properties object and bind it in JNDI.

      I have tried the following, but this does not work. It does not bind my properties object. What am I doing wrong here?

      Thanks,
      -Scott

      [...]

      Properties jprops = new Properties();
      jprops.setProperty( "java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
      jprops.setProperty( "java.naming.provider.url","localhost:1099");
      jprops.setProperty( "java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");

      Properties props = new Properties();
      try {
      URL uconf = new URL(CONF_DIR+"bqconf.properties");
      props.load(uconf.openStream());
      }
      catch(MalformedURLException e) {
      System.out.println("Malformed URL!");
      e.printStackTrace();
      }
      catch(IOException e){
      System.out.println("No properties file present!");
      System.out.println("FILE: "+CONF_DIR+"bqconf.properties");
      }

      try {
      InitialContext context = new InitialContext(jprops);
      context.bind("java:mailproperties",props);
      }
      catch(NamingException e){
      e.printStackTrace();
      }

      try {
      InitialContext context = new InitialContext(jprops);
      context.lookup("java:mailerproperties");
      System.out.println("Properties Bound!");
      }
      catch(NamingException e){
      System.out.println("Naming Exception: "+e.getMessage());
      }

      [...]