5 Replies Latest reply on Sep 1, 2003 2:48 AM by azydron

    Cannot instantiate class: .

    azydron Newbie


      We are experiencing javax.naming.NoInitialContextException exceptions under load running jboss-3.0.7_jakarta-tomcat-4.1.24 when trying to instantiate stateless session beans.

      The errors are not consistent but apear to be related to system load. The specific error message does not give a class name the Exception message is:

      javax.naming.NoInitialContextException: Cannot instantiate class: . Root exception is
      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.(InitialContext.java:178)

      Our environment is as follows:

      O/S: SunOS 5.8 Generic_108528-09 sun4u sparc SUNW,Ultra-4

      Java: Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)

      JBoss Bootstrap Environment

      JBOSS_HOME: /export/home/jboss/jboss-3.0.7_jakarta-tomcat-4.1.24

      JAVA: /usr/java//bin/java

      JAVA_OPTS: -Xmx1024M -verbosegc -Dprogram.name=run.sh

      CLASSPATH: /export/home/jboss/config//xercesImpl.jar:/export/home/jboss/config

      An example of the InitialContext connection code is:

      InitialContext iniCtx = new InitialContext();

      Object ref = iniCtx.lookup("java:comp/env/jdbc/TerminologyDS");

      We would appreciate some help and guidance as to the best way to circumvent this error.

      Thanks in advance,


        • 1. Re: Cannot instantiate class: .
          T. C. Link Newbie

          You need a jndi.properties file in your WEB-INF/lib that specifies the following parameters:

          java.naming.factory.initial = org.jnp.interfaces.NamingContextFactory
          java.naming.provider.url = jnp://localhost:1099

          • 2. Re: Cannot instantiate class: .
            azydron Newbie

            Thank you for your reply. The applications in question do not run as part of a web service, but are normal EJB's. The error occurs when trying to instatiate the objects from client code. We will give it a try though.



            • 3. Re: Cannot instantiate class: .
              azydron Newbie

              Made no difference - this is a real problem. The clue may be in the ":." has anybody seen anything like this?

              • 4. Re: Cannot instantiate class: .
                Weston Price Newbie

                Could you be a bit more specific. I assume what you are trying to do is use StateLess Session Beans from a Remote Clent, some form of unit test. From you error, the problem at this point is twofold:

                First off:
                You need to have jbossclient-all.jar in your classpath. This provides you with the jboss class that implements the InitialContext interface.

                If you are indeed running a standalone client, what you need to set a few VM properties before you execute your code. They are:


                You would execute this in the following manner:

                java $YOURCLASSPATH -Dproperty1 -Dproperty2 classtoexecute

                As was previously mentioned, you could create a jndi.properties file and put it in your CLASSPATH or to test you could do it from the command line.Also, unless you have your RMIClassLoader enabled, you shoudl have the ejb.jar file that contains the interfaces to the StatelessSession Beans in your java CLASSPATH as well. Otherwise the stubs will have to be serialzed and sent to the client VM which requires extra setup.
                Now, if you are not running a standalone client, but are trying to access an EJB from as Servelt, this is an entirely different error. If you can't get an InitialContext, then something is probably wrong with the way Tomcat-->JBoss is configured.
                How are you starting JBoss, are you using the run.sh script or to you have your own "home grown" version of a startup routine?



                • 5. Re: Cannot instantiate class: .
                  azydron Newbie

                  Hi Weston,

                  Thank you very much for your reply and advice. In response to your questions:

                  1) Yes, the errors are to do with StateLess Session beans.
                  2) jbossclient-all.jar is in the client's classpath.
                  3) The parameters for the client's VM are:
                  -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory \
                  -Djava.naming.provider.url=jnp://jobsserver:1099 \
                  -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces \

                  and are set like this on the command line.
                  4) The ejb.jar is in the client's CLASSPATH

                  We traced the error to a NamingException in the Stateless Session Beans' getConnection() method so we put in the following fix:

                  iniCtx = new InitialContext();
                  ref = iniCtx.lookup(dataSourceName);
                  catch (NamingException ne)
                  logger.warn("Couldn't get the datasource "+dataSourceName+" retrying in 5 seconds - ", ne);
                  catch(InterruptedException ie)
                  // Do nothing
                  iniCtx = new InitialContext();
                  ref = iniCtx.lookup(dataSourceName);

                  On the second retry it always works, but we would like to fix this properly.

                  Thanks in advance,