1 Reply Latest reply on Jan 2, 2005 5:28 PM by Ohad Raz

    NoInitialContextException: Cannot instantiate class: org.jnp

    Ohad Raz Newbie

      Hello all,

      I really need some help here.
      I am totally new to both J2EE and JBoss.
      I am reading Matering Enterprise JavaBean to learn J2EE, and I tried the "Writing Your First Bean". It should be real simple, but still I cannot get it to work...

      Jboss starts with no exceptions and with no errors, but there's this warning:

      19:56:02,965 WARN [NamingService] Context.PROVIDER_URL in server jndi.properties, url=localhost:1099

      When I try to run the test client, I get the following exception:
      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.<init>(InitialContext.java:195)
      at examples.HelloClient.main(HelloClient.java:44)
      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)
      ... 4 more
      Exception in thread "main"

      My client is as simple as can be:
      public static void main(String[] args) throws Exception{
       Properties props= System.getProperties();
       Context ctx= new InitialContext(props);
       Object obj= ctx.lookup("java:comp/env/ejb/Hello");
       HelloHome home= (HelloHome) PortableRemoteObject.narrow(obj, HelloHome.class);
      
       //etc...

      I added the /conf directory to the classpath, so to have jndi.properties.
      My jndi.properties is:
      # DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
      #
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=jnp://localhost:1099
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

      The codes are copied from the Mastering Enterprise JavaBean book, and the content of jndi.properties is copied from the Getting Started with JBoss document.
      As for my decision to add the /conf directory to the classpath, well, I had other Exception before that, and I read in the forum that the jndi.properties should be added to the classpath.

      It all seems to be like it should be, but it is just not working.
      Anyone has ideas what went wrong?
      Would appreciate any help.

      Kind regards,
      Ohad