3 Replies Latest reply on Jan 14, 2005 9:31 AM by darranl

    Problem setting InitialContext

      Hi,


      I'm new to EJB. Having developed and set up a BMP ejb class following books, I try to test it with a simple client, TestClient below. I've not really coded much in the TestClient. But I got a javax.naming.NoInitialContextException when run it pointing problem on the InitalContext() line.

      Pls help. Thanks in advance,
      jackling


      the TestClient:

      package com.gc.client;

      import java.util.Collection;
      import java.util.Iterator;
      import javax.naming.InitialContext;
      import com.gc.ejb.*;
      import com.gc.interfaces.*;


      public class TestClient {
      public static void main(String[] args) throws Exception {
      Object countrybmp = new InitialContext().lookup("ejb/CountryBMP");
      }
      }




      the Error:



      java -classpath C:\eclipse\workspace\JUnit\gCopper\bin;C:\jboss-3.2.5\server\default\lib\jboss-j2ee.jar com.gc.client.TestClient

      Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or i
      n an application resource file: java.naming.factory.initial
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at com.gc.client.TestClient.main(TestClient.java:24)

        • 1. Re: Problem setting InitialContext

          Hi,

          I've tried setting jndi.properties. But then it still comes up with the following ClassNotFoundException. Pls help!



          Exception in thread "main" javax.naming.NoInitialContextException: Cannot instan
          tiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lan
          g.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
          at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
          at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
          at javax.naming.InitialContext.init(Unknown Source)
          at javax.naming.InitialContext.(Unknown Source)
          at com.gc.client.TestClient.main(TestClient.java:35)
          Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFac
          tory
          at java.net.URLClassLoader$1.run(Unknown Source)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at java.lang.ClassLoader.loadClassInternal(Unknown Source)
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Unknown Source)
          at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
          ... 5 more

          • 2. Re: Problem setting InitialContext
            frito

            You shouldn't skip the theory before implementing the book examples ;-)
            The InitialContext needs some information about the naming service implementation used:

            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
            


            Set these properties as system properties or pass a Properties object as parameter when creating a new InitialContext(Properties).

            • 3. Re: Problem setting InitialContext
              darranl

              Your latest error is saying that the class specified can not be found so your jndi.properties file is being read.

              Try changing your classpath, remove the jar 'server\default\lib\jboss-j2ee.jar' and add the jar 'client\jbossall-client.jar'