7 Replies Latest reply on May 23, 2006 1:00 AM by jaikiran pai

    javax.naming.NoInitialContextException: Cannot instantiate c

    saeedamer Newbie

      I have seen so many posts regarding this problem but none contained a solution.

      I am using jboss-3.0.6_tomcat-4.1.18. The jndi.properties file in the server\default\conf directory contains:
      ------ jndi.properties ----------
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      # Do NOT uncomment this line as it causes in VM calls to go over
      # RMI!
      #java.naming.provider.url=localhost
      --------------------

      When I create InitialContext like this:
      new javax.naming.InitialContext()

      I get following error:
      ------error------
      javax.naming.CommunicationException: Can't find SerialContextProvider
      at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.java:63)
      at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:120)
      at javax.naming.InitialContext.lookup(InitialContext.java:347) at Client_1.main(Client_1.java:32)
      --------------

      And when I setup the JNDI properties as follows and create InitialContext:
      --------
      props.put ("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      props.put("java.naming.provider.url", "127.0.0.1:1099");

      new javax.naming.InitialContext(prop);
      --------

      I get following error:
      -------error---------
      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
      at javax.naming.InitialContext.init(InitialContext.java:219)
      at javax.naming.InitialContext.(InitialContext.java:195)
      at Client_1.getInitialContext(Client_1.java:84)
      at Client_1.main(Client_1.java:30)
      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:219)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
      ... 5 more
      ---------------------------

      It seems that something is missing in the classpath. BTW, I am not relying on the CLASSPATH env variable - I am relying on JBoss to load all the JAR files on its path in "server\default\lib" directory.

      I have been banging my head for almost 12 hours now and haven't got anywahere.

      Help is greatly appreciated.

      Amer