You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Alistair Bayley <ab...@bigfoot.com> on 2001/10/04 21:39:45 UTC

Help: JNDI InitialContext failure with Tomcat 3.2.3 and JBoss 2.4.1

[ Sent this once already but it didn't appear on the list so here we go 
again... ]

I'm getting this in my tomcat.log when creating the jndi InitialContext:


javax.naming.NoInitialContextException: Cannot instantiate class:
org.jnp.interfaces.NamingContextFactory.  Root exception is
java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        .... [full listing below, annotated]


Does this imply that the container is using a different classloader than the
one used when I create the "temp" NamingContextException in the
ServiceLocator? (see code below) If so, why? I see java.net.URLClassLoader in 
the stacktrace; is this significant?

I want to get the Home interface for an EJB in a JBoss server on the same
machine. I have been able to write a standalone java class that obtains the
Home interface and tests it, and it works fine, so the problem doesn't appear
to be with JBoss (this stanalone class has the JBoss client jars in its 
classpath).

In my WEB-INF/lib directory I have: jboss-j2ee.jar (from jboss), 
jnp-client.jar (from jboss), junit.jar, timerec.jar (my app, which has the 
ServiceLocator and other classes), jndi.properties (from JBoss).

I use the following ServiceLocator (see the getContext method), and I use
this jndi.properties file:


---- Start jndi.properties -------------------------------------
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
---- End jndi.properties -------------------------------------



---- Start code --------------------------------------------
import javax.rmi.PortableRemoteObject;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.ejb.EJBHome;
import timerec.shared.ServiceLocatorException;

// Home objects used for type-safety:
import timerec.business.UserEntityHome;
import timerec.service.AuthenticateSessionHome;

// A type-safe ServiceLocator.
// New services MUST be added to this.

public class ServiceLocator {
  private static Context _context;
  private static ServiceLocator _one;

  // This is a singleton.
  private ServiceLocator() {
  }
  public static ServiceLocator getInstance() {
    if (_one == null) { _one = new ServiceLocator(); }
    return _one;
  }

  static public class Service {
    private String _binding;
    private Class _class;
    private Service(String binding, Class c)
      { _binding = binding; _class = c; }
    public String getBinding() { return _binding; }
    public Class getServiceClass() { return _class; }
  }

  // Entity Beans
  public final static Service User =
    new Service("TimeRec/User", UserEntityHome.class);

  // Session Beans
  public final static Service Authenticate =
    new Service("TimeRec/Authenticate", AuthenticateSessionHome.class);



  // Getting an InitialContext is expensve, so it is cached in this class.
  public static Context getContext() throws NamingException {
    if ( _context != null ) return _context;

    // Check that
    // (1) jndi.properties file is being read
    // (2) org.jnp.interfaces.NamingContextFactory is available on classpath
    System.out.println(
      "getContext: property for java.naming.factory.initial:");
    System.out.println(System.getProperty("java.naming.factory.initial"));
    System.out.println("ServiceLocator: creating NamingContextFactory:");
    org.jnp.interfaces.NamingContextFactory temp =
      new org.jnp.interfaces.NamingContextFactory();
    System.out.println("ServiceLocator: created NamingContextFactory.");

    Context c = new InitialContext();
    // Don't do this - comp:java is not bound
    //c.lookup("comp:java/env");
    return c;
  }


  public static EJBHome getHome(Service s) throws ServiceLocatorException {
    EJBHome home = null;
    Object obj;
    try {
      obj = getContext().lookup(s.getBinding());
      home = (EJBHome) PortableRemoteObject.narrow(obj, s.getServiceClass());
    } catch (NamingException e) {
      e.printStackTrace();
      throw new ServiceLocatorException(
        "Unable to locate Home interface for " + s.getBinding());
    }
    return home;
  }

}

---- End code --------------------------------------------




---- Start output --------------------------------------------

getContext: property for java.naming.factory.initial:
org.jnp.interfaces.NamingContextFactory
ServiceLocator: creating NamingContextFactory:
ServiceLocator: created NamingContextFactory.
javax.naming.NoInitialContextException: Cannot instantiate class:
org.jnp.interfaces.NamingContextFactory.  Root exception is
java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:195)
	at
 com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:45)
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246) at
 javax.naming.InitialContext.init(InitialContext.java:222)
	at javax.naming.InitialContext.<init>(InitialContext.java:178)
	at timerec.shared.ServiceLocator.getContext(ServiceLocator.java:62)

>>>>       ^^^^^^^^ My ServiceLocator class

	at timerec.shared.ServiceLocator.getHome(ServiceLocator.java:73)
	at timerec.presentation.LoginDelegate.authenticate(LoginDelegate.java:26)
	at
WEB_0002dINF.jsp._0002fWEB_0002dINF_0002fjsp_0002floginDispatcher_0002ejsplog
inDispatcher_jsp_12._jspService(_0002fWEB_0002dINF_0002fjsp_0002floginDispatc
her_0002ejsploginDispatcher_jsp_12.java:90) at
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119) at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.jav
a:130) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.jav
a:282) at
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429) at
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500) at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
	at org.apache.tomcat.core.Handler.service(Handler.java:287)
	at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
	at
org.apache.tomcat.facade.RequestDispatcherImpl.doForward(RequestDispatcherImp
l.java:222) at
org.apache.tomcat.facade.RequestDispatcherImpl.forward(RequestDispatcherImpl.
java:162) at
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:421)
	at
_0002ftrcontroller_0002ejsptrcontroller_jsp_19._jspService(_0002ftrcontroller
_0002ejsptrcontroller_jsp_19.java:65) at
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119) at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.jav
a:130) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.jav
a:282) at
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429) at
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500) at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
	at org.apache.tomcat.core.Handler.service(Handler.java:287)
	at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
	at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812
) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
 at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(
Ajp12ConnectionHandler.java:166) at
 org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416) at
 org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
 at java.lang.Thread.run(Thread.java:484)

---- End output --------------------------------------------