This discussion is archived
2 Replies Latest reply: Dec 8, 2010 6:52 AM by gimbal2 RSS

Tomcat to Glassfish not working

807254 Newbie
Currently Being Moderated
Hello I am trying to connect to a remote ejb from tomcat 6 with the ejb residing on glassfish 3.I am using the guide at [glassfish |https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#nonJavaEEwebcontainerRemoteEJB] for advice.
My servers tomcat 6 and glassfish 3 are running on different ports and are on the same machine running on localhost.I want to get the most current technique to connect to a ejb in glassfish 3.I have tried to implement and use parts of tutorials but have not found one answer sufficient to my use.

I am using netbeans 6.9.I have followed he steps laid out in the glassfish guide.I have read to just include the gf-client.jar file which includes links to needed files.
here STEP 3:

"Note that the Java EE 6 API classes are automatically included by gf-client.jar so there is no need to explicitly add javaee.jar to the classpath. gf-client.jar refers to many other .jars from the GlassFish installation directory so it is best to refer to it from within the installation directory itself rather than copying it(and all the other .jars) to another location."

This is what I am doing.
I have tried using the appserv-rt.jar file to remove the java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory.Though I don`t know the best way in that I got another error.

What library files do I include and where do I include them.I have included my ejb netbeans ejb.jar file so I just need the right libraries in the right places.Please offer you opinion and suggestions.

calling code
Context ic = null;
 
            Properties props = new Properties();
 
            props.setProperty("java.naming.factory.initial",
                    "com.sun.enterprise.naming.SerialInitContextFactory");
 
            props.setProperty("java.naming.factory.url.pkgs",
                    "com.sun.enterprise.naming");
 
            props.setProperty("java.naming.factory.state",
                    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
 
            // optional.  Defaults to localhost.  Only needed if web server is running
            // on a different host than the appserver
            props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
 
            // optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
            props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
 
            ic = new  InitialContext(props);
 
         try{
 
            ExpoServiceFacadeRemote foo = (ExpoServiceFacadeRemote)ic.lookup(ExpoServiceFacadeRemote.class.getName());
      
            foo.toString();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
         
            out.close();
        }
    }
here I got an error in
ic = new  InitialContext(props);
SEVERE: null
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at Controller.com.processRequest(com.java:62)
        at Controller.com.doGet(com.java:89)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
        ... 19 more
thanks
  • 1. Re: Tomcat to Glassfish not working
    807254 Newbie
    Currently Being Moderated
    Hello still looking into this is there some extra known setup restrictions
    Cheers
  • 2. Re: Tomcat to Glassfish not working
    gimbal2 Guru
    Currently Being Moderated
    java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
    Java cannot make it any more clear to you: this class does not exist in the classpath of your application, so it cannot do its work. If you don't know how to deal with classnotfound errors, I suggest you put a little research into that topic as you'll be seeing it a lot when you continue to use Java.

    You need a certain jar or multiple jars from the glassfish server that contain all the JNDI provider classes and make those available to your client application. I'm not very familiar with Glassfish, but a quick google search turned up the name 'gf-client.jar' which seems very logical.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points