6 Replies Latest reply on May 26, 2005 8:29 AM by ilangocal

    javax.naming.NoInitialContextException: Cannot instantiate c

    rawat_tejinder


      while running a client application for my j2ee application on the jboss i am getting following type of error:

      >>> Source code start here
      package au.com.chimo.nextidserver.wsclienttest;

      import javax.naming.Context;
      import java.util.Properties;

      /**
      * Created by IntelliJ IDEA.
      * User: shaun
      * Date: 21/07/2004
      * Time: 14:27:35
      */
      public class EJBBaseTest {

      protected Properties properties = null;
      public EJBBaseTest(){
      super();
      properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY,

      "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      }

      }

      >>> Source code end here

      >>> Stack error trace(start here)
      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
      aces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: o
      rg.jnp.interfaces.NamingContextFactory]
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
      52)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
      )
      at javax.naming.InitialContext.init(InitialContext.java:219)
      at javax.naming.InitialContext.(InitialContext.java:195)
      at au.com.chimo.nextidserver.wsclienttest.EJBRegisterUserTest.(Unk
      nown Source)
      at au.com.chimo.nextidserver.wsclienttest.EJBRegisterUserTest$MyThread.r
      un(Unknown Source)
      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFac
      tory
      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.jav
      a:42)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
      49)
      ... 5 more




      >>> there is lot of stack trace of this type

        • 1. Re: javax.naming.NoInitialContextException: Cannot instantia
          darranl

          ClassNotFoundException

          Add the jbossall-client.jar from the client folder to the classpath of your client.

          • 2. Re: javax.naming.NoInitialContextException: Cannot instantia
            rawat_tejinder

            it is already there in the classpath

            • 3. Fixed for my
              milton.jboss

              its true, it's succefull puting in the classpath jbossall-client.jar

              Milton Labanda
              Loja Ecuador
              1000ton@mail.com

              • 4. Re: javax.naming.NoInitialContextException: Cannot instantia

                Hi Rawat
                I have a similar problem, because Apache is giving me the same error. I am running JBoss 2.4.2 though. Please let me know whether you got your problem and how you went out solving this:

                My problem goes like this:

                I have been unable to get Budi Kurniawan's application to read anything from the database TassieDB . I am not sure what is wrong. I downloaded the database from the CD. Then since this was an older version of Access, I had to let my Access convert it to the newer form.

                I then configured the Database the way I thought I should in order for it to work. I created a Data Source Name called TassieDB, by following the procedure to create a System DSN on Windows. I selected the Microsoft Access Driver and associated my Database which I named TassieDB1, which I deposited under C:\budibookstore which also contains the package com.brainysoftware.tassie.servlet.ejb

                When I access the SearchServlet page and type in "Computer" in the search box nothing turns up. I wonder what is going on?

                The following errors are spewed out by Apache in this process:

                May 18, 2005 8:27:24 PM org.apache.coyote.http11.Http11Protocol init
                INFO: Initializing Coyote HTTP/1.1 on http-8080
                Starting service Tomcat-Standalone
                Apache Tomcat/4.1.31
                May 18, 2005 8:27:28 PM org.apache.struts.util.PropertyMessageResources
                INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=tru
                e
                May 18, 2005 8:27:28 PM org.apache.struts.util.PropertyMessageResources
                INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNul
                l=true
                May 18, 2005 8:27:29 PM org.apache.struts.util.PropertyMessageResources
                INFO: Initializing, config='org.apache.webapp.admin.ApplicationResources', retur
                nNull=true
                May 18, 2005 8:27:33 PM org.apache.coyote.http11.Http11Protocol start
                INFO: Starting Coyote HTTP/1.1 on http-8080
                May 18, 2005 8:27:33 PM org.apache.jk.common.ChannelSocket init
                INFO: JK2: ajp13 listening on /0.0.0.0:8009
                May 18, 2005 8:27:33 PM org.apache.jk.server.JkMain start
                INFO: Jk running ID=0 time=10/150 config=C:\tomcatj\conf\jk2.properties
                javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: o
                rg.jnp.interfaces.NamingContextFactory]
                javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
                aces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: o
                rg.jnp.interfaces.NamingContextFactory]


                ----------

                Thanks in advance

                • 5. Re: javax.naming.NoInitialContextException: Cannot instantia
                  rawat_tejinder

                  hello ilangocal,
                  it is a configuration problem, make sure that you have configured the things apprpriately, send the more details if you have not got the solution yet.

                  • 6. new problem

                    Hi Rawat
                    I managed to solve this problem, with the use of the proper jars in their respective places.
                    However I now have a new problem. I keep getting HTTP status code 404 in my pages. I have a package structure as follows: ( i have not used a WAR file)

                    C:\tomcatj\webapps\bookstore\WEB-INF\classes\com\brainysoftware\tassie\ejb

                    here bookstore is my document base. I also have a directory called servlets under tassie called servlets under which I store all the servlet class files.

                    now com\brainysoftware\tassie\ejb
                    and com\brainysoftware\tassie\servlet

                    are the packages that i use in the servlet java files and the EJBs.

                    I suspect that I am unable to load my pages because of a possible error in the Context path setting in the server.xml. My server.xml file is as follows:




                    <!-- Comment these entries out to disable JMX MBeans support -->
                    <!-- You may also configure custom components (e.g. Valves/Realms) by
                    including your own mbean-descriptor file(s), and setting the
                    "descriptors" attribute to point to a ';' seperated list of paths
                    (in the ClassLoader sense) of files to add to the default list.
                    e.g. descriptors="/com/myfirm/mypackage/mbean-descriptor.xml"
                    -->


                    <!-- Global JNDI resources -->

                    <!-- Test entry for demonstration purposes -->

                    <!-- Editable user database that can also be used by
                    UserDatabaseRealm to authenticate users -->



                    factory
                    org.apache.catalina.users.MemoryUserDatabaseFactory


                    pathname
                    conf/tomcat-users.xml



                    <!-- A "Service" is a collection of one or more "Connectors" that share
                    a single "Container" (and therefore the web applications visible
                    within that Container). Normally, that Container is an "Engine",
                    but this is not required.

                    Note: A "Service" is not itself a "Container", so you may not
                    define subcomponents such as "Valves" or "Loggers" at this level.
                    -->
                    <!-- Define the Tomcat Stand-Alone Service -->

                    <!-- A "Connector" represents an endpoint by which requests are received
                    and responses are returned. Each Connector passes requests on to the
                    associated "Container" (normally an Engine) for processing.

                    By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
                    You can also enable an SSL HTTP/1.1 Connector on port 8443 by
                    following the instructions below and uncommenting the second Connector
                    entry. SSL support requires the following steps (see the SSL Config
                    HOWTO in the Tomcat 4.0 documentation bundle for more detailed
                    instructions):
                    * Download and install JSSE 1.0.2 or later, and put the JAR files
                    into "$JAVA_HOME/jre/lib/ext".
                    * Execute:
                    %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
                    $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA (Unix)
                    with a password value of "changeit" for both the certificate and
                    the keystore itself.

                    By default, DNS lookups are enabled when a web application calls
                    request.getRemoteHost(). This can have an adverse impact on
                    performance, so you can disable it by setting the
                    "enableLookups" attribute to "false". When DNS lookups are disabled,
                    request.getRemoteHost() will return the String version of the
                    IP address of the remote client.
                    -->
                    <!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->

                    <!-- Note : To disable connection timeouts, set connectionTimeout value
                    to 0 -->
                    <!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
                    <!--



                    -->
                    <!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->

                    <!-- Define an AJP 1.3 Connector on port 8009 -->
                    <!--

                    -->
                    <!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
                    <!-- See proxy documentation for more information about using this. -->
                    <!--

                    -->
                    <!-- Define a non-SSL legacy HTTP/1.1 Test Connector on port 8083 -->
                    <!--

                    -->
                    <!-- Define a non-SSL HTTP/1.0 Test Connector on port 8084 -->
                    <!--

                    -->
                    <!-- An Engine represents the entry point (within Catalina) that processes
                    every request. The Engine implementation for Tomcat stand alone
                    analyzes the HTTP headers included with the request, and passes them
                    on to the appropriate Host (virtual host). -->
                    <!-- You should set jvmRoute to support load-balancing via JK/JK2 ie :

                    -->
                    <!-- Define the top level container in our container hierarchy -->

                    <!-- The request dumper valve dumps useful debugging information about
                    the request headers and cookies that were received, and the response
                    headers and cookies that were sent, for all requests received by
                    this instance of Tomcat. If you care only about requests to a
                    particular virtual host, or a particular application, nest this
                    element inside the corresponding or entry instead.

                    For a similar mechanism that is portable to all Servlet 2.3
                    containers, check out the "RequestDumperFilter" Filter in the
                    example application (the source for this filter may be found in
                    "$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").

                    Request dumping is disabled by default. Uncomment the following
                    element to enable it. -->
                    <!--

                    -->
                    <!-- Global logger unless overridden at lower levels -->

                    <!-- Because this Realm is here, an instance will be shared globally -->
                    <!-- This Realm uses the UserDatabase configured in the global JNDI
                    resources under the key "UserDatabase". Any edits
                    that are performed against this UserDatabase are immediately
                    available for use by the Realm. -->

                    <!-- Comment out the old realm but leave here for now in case we
                    need to go back quickly -->
                    <!--

                    -->
                    <!-- Replace the above Realm with one of the following to get a Realm
                    stored in a database and accessed via JDBC -->
                    <!--

                    -->
                    <!--

                    -->
                    <!--

                    -->
                    <!-- Define the default virtual host -->

                    <!-- Normally, users must authenticate themselves to each web app
                    individually. Uncomment the following entry if you would like
                    a user to be authenticated the first time they encounter a
                    resource protected by a security constraint, and then have that
                    user identity maintained across *all* web applications contained
                    in this virtual host. -->
                    <!--

                    -->
                    <!-- Access log processes all requests for this virtual host. By
                    default, log files are created in the "logs" directory relative to
                    $CATALINA_HOME. If you wish, you can specify a different
                    directory with the "directory" attribute. Specify either a relative
                    (to $CATALINA_HOME) or absolute path to the desired directory.
                    -->
                    <!--

                    -->
                    <!-- Logger shared by all Contexts related to this virtual host. By
                    default (when using FileLogger), log files are created in the "logs"
                    directory relative to $CATALINA_HOME. If you wish, you can specify
                    a different directory with the "directory" attribute. Specify either a
                    relative (to $CATALINA_HOME) or absolute path to the desired
                    directory.-->

                    <!-- Define properties for each web application. This is only needed
                    if you want to set non-default properties, or have web application
                    document roots in places other than the virtual host's appBase
                    directory. -->
                    <!-- Tomcat Root Context -->

                    <!-- Tomcat Examples Context -->
                    <!--



                    -->


                    <!-- If you wanted the examples app to be able to edit the
                    user database, you would uncomment the following entry.
                    Of course, you would want to enable security on the
                    application as well, so this is not done by default!
                    The database object could be accessed like this:

                    Context initCtx = new InitialContext();
                    Context envCtx = (Context) initCtx.lookup("java:comp/env");
                    UserDatabase database =
                    (UserDatabase) envCtx.lookup("userDatabase");
                    -->
                    <!--

                    -->
                    <!-- PersistentManager: Uncomment the section below to test Persistent
                    Sessions.

                    saveOnRestart: If true, all active sessions will be saved
                    to the Store when Catalina is shutdown, regardless of
                    other settings. All Sessions found in the Store will be
                    loaded on startup. Sessions past their expiration are
                    ignored in both cases.
                    maxActiveSessions: If 0 or greater, having too many active
                    sessions will result in some being swapped out. minIdleSwap
                    limits this. -1 or 0 means unlimited sessions are allowed.
                    If it is not possible to swap sessions new sessions will
                    be rejected.
                    This avoids thrashing when the site is highly active.
                    minIdleSwap: Sessions must be idle for at least this long
                    (in seconds) before they will be swapped out due to
                    activity.
                    0 means sessions will almost always be swapped out after
                    use - this will be noticeably slow for your users.
                    maxIdleSwap: Sessions will be swapped out if idle for this
                    long (in seconds). If minIdleSwap is higher, then it will
                    override this. This isn't exact: it is checked periodically.
                    -1 means sessions won't be swapped out for this reason,
                    although they may be swapped out for maxActiveSessions.
                    If set to >= 0, guarantees that all sessions found in the
                    Store will be loaded on startup.
                    maxIdleBackup: Sessions will be backed up (saved to the Store,
                    but left in active memory) if idle for this long (in seconds),
                    and all sessions found in the Store will be loaded on startup.
                    If set to -1 sessions will not be backed up, 0 means they
                    should be backed up shortly after being used.

                    To clear sessions from the Store, set maxActiveSessions, maxIdleSwap,
                    and minIdleBackup all to -1, saveOnRestart to false, then restart
                    Catalina.
                    -->
                    <!--



                    -->





                    username
                    sa


                    password



                    driverClassName
                    org.hsql.jdbcDriver


                    url
                    jdbc:HypersonicSQL:database





                    mail.smtp.host
                    localhost










                    I have attached my server.log file details too.


                    005-05-26 05:13:45 StandardHost[localhost]: Removing web application at context path /admin
                    2005-05-26 05:13:45 StandardHost[localhost]: Removing web application at context path /webdav
                    2005-05-26 05:13:45 StandardHost[localhost]: Removing web application at context path /bookstore
                    2005-05-26 05:13:45 StandardHost[localhost]: Removing web application at context path /examples
                    2005-05-26 05:13:45 SessionListener: contextDestroyed()
                    2005-05-26 05:13:45 ContextListener: contextDestroyed()
                    2005-05-26 05:13:45 StandardHost[localhost]: Removing web application at context path /tomcat-docs
                    2005-05-26 05:13:45 StandardHost[localhost]: Removing web application at context path /manager
                    2005-05-26 05:13:45 StandardHost[localhost]: Removing web application at context path
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploying class repositories to work directory C:\tomcatj\work\Standalone\localhost\bookstore
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploy class files /WEB-INF/classes to C:\tomcatj\webapps\bookstore\WEB-INF\classes
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploy JAR /WEB-INF/lib/TestBeanClient.jar to C:\tomcatj\webapps\bookstore\WEB-INF\lib\TestBeanClient.jar
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploy JAR /WEB-INF/lib/jboss-client.jar to C:\tomcatj\webapps\bookstore\WEB-INF\lib\jboss-client.jar
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploy JAR /WEB-INF/lib/jboss-j2ee.jar to C:\tomcatj\webapps\bookstore\WEB-INF\lib\jboss-j2ee.jar
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploy JAR /WEB-INF/lib/jbossmq-client.jar to C:\tomcatj\webapps\bookstore\WEB-INF\lib\jbossmq-client.jar
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploy JAR /WEB-INF/lib/jbosssx-client.jar to C:\tomcatj\webapps\bookstore\WEB-INF\lib\jbosssx-client.jar
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploy JAR /WEB-INF/lib/jndi.jar to C:\tomcatj\webapps\bookstore\WEB-INF\lib\jndi.jar
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploy JAR /WEB-INF/lib/jnp-client.jar to C:\tomcatj\webapps\bookstore\WEB-INF\lib\jnp-client.jar
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Deploy JAR /WEB-INF/lib/jta.jar to C:\tomcatj\webapps\bookstore\WEB-INF\lib\jta.jar
                    2005-05-26 05:13:52 WebappLoader[/bookstore]: Reloading checks are enabled for this Context
                    2005-05-26 05:13:53 StandardManager[/bookstore]: Seeding random number generator class java.security.SecureRandom
                    2005-05-26 05:13:53 StandardManager[/bookstore]: Seeding of random number generator has been completed
                    2005-05-26 05:13:53 StandardWrapper[/bookstore:default]: Loading container servlet default
                    2005-05-26 05:13:54 StandardWrapper[/bookstore:invoker]: Loading container servlet invoker
                    2005-05-26 05:13:54 WebappLoader[]: Deploying class repositories to work directory C:\tomcatj\work\Standalone\localhost\_
                    2005-05-26 05:13:54 StandardManager[]: Seeding random number generator class java.security.SecureRandom
                    2005-05-26 05:13:54 StandardManager[]: Seeding of random number generator has been completed
                    2005-05-26 05:13:54 StandardWrapper[:default]: Loading container servlet default
                    2005-05-26 05:13:54 StandardWrapper[:invoker]: Loading container servlet invoker
                    2005-05-26 05:13:54 HostConfig[localhost]: Deploying configuration descriptor admin.xml
                    2005-05-26 05:13:59 HostConfig[localhost]: Deploying configuration descriptor manager.xml
                    2005-05-26 05:13:59 WebappLoader[/manager]: Deploying class repositories to work directory C:\tomcatj\work\Standalone\localhost\manager
                    2005-05-26 05:13:59 ContextConfig[/manager]: Configured an authenticator for method BASIC
                    2005-05-26 05:13:59 StandardManager[/manager]: Seeding random number generator class java.security.SecureRandom
                    2005-05-26 05:13:59 StandardManager[/manager]: Seeding of random number generator has been completed
                    2005-05-26 05:13:59 StandardWrapper[/manager:default]: Loading container servlet default
                    2005-05-26 05:13:59 StandardWrapper[/manager:invoker]: Loading container servlet invoker
                    2005-05-26 05:13:59 HostConfig[localhost]: Deploying web application directory examples
                    2005-05-26 05:13:59 StandardHost[localhost]: Installing web application at context path /examples from URL file:C:\tomcatj\webapps\examples
                    2005-05-26 05:13:59 WebappLoader[/examples]: Deploying class repositories to work directory C:\tomcatj\work\Standalone\localhost\examples
                    2005-05-26 05:13:59 WebappLoader[/examples]: Deploy class files /WEB-INF/classes to C:\tomcatj\webapps\examples\WEB-INF\classes
                    2005-05-26 05:14:00 ContextConfig[/examples]: Configured an authenticator for method FORM
                    2005-05-26 05:14:00 StandardManager[/examples]: Seeding random number generator class java.security.SecureRandom
                    2005-05-26 05:14:00 StandardManager[/examples]: Seeding of random number generator has been completed
                    2005-05-26 05:14:00 ContextListener: contextInitialized()
                    2005-05-26 05:14:00 SessionListener: contextInitialized()
                    2005-05-26 05:14:00 StandardWrapper[/examples:default]: Loading container servlet default
                    2005-05-26 05:14:00 StandardWrapper[/examples:invoker]: Loading container servlet invoker
                    2005-05-26 05:14:00 HostConfig[localhost]: Deploying web application directory tomcat-docs
                    2005-05-26 05:14:00 StandardHost[localhost]: Installing web application at context path /tomcat-docs from URL file:C:\tomcatj\webapps\tomcat-docs
                    2005-05-26 05:14:00 WebappLoader[/tomcat-docs]: Deploying class repositories to work directory C:\tomcatj\work\Standalone\localhost\tomcat-docs
                    2005-05-26 05:14:00 StandardManager[/tomcat-docs]: Seeding random number generator class java.security.SecureRandom
                    2005-05-26 05:14:00 StandardManager[/tomcat-docs]: Seeding of random number generator has been completed
                    2005-05-26 05:14:00 StandardWrapper[/tomcat-docs:default]: Loading container servlet default
                    2005-05-26 05:14:00 StandardWrapper[/tomcat-docs:invoker]: Loading container servlet invoker
                    2005-05-26 05:14:00 HostConfig[localhost]: Deploying web application directory webdav
                    2005-05-26 05:14:00 StandardHost[localhost]: Installing web application at context path /webdav from URL file:C:\tomcatj\webapps\webdav
                    2005-05-26 05:14:00 WebappLoader[/webdav]: Deploying class repositories to work directory C:\tomcatj\work\Standalone\localhost\webdav
                    2005-05-26 05:14:01 StandardManager[/webdav]: Seeding random number generator class java.security.SecureRandom
                    2005-05-26 05:14:01 StandardManager[/webdav]: Seeding of random number generator has been completed
                    2005-05-26 05:14:01 StandardWrapper[/webdav:default]: Loading container servlet default
                    2005-05-26 05:14:01 StandardWrapper[/webdav:invoker]: Loading container servlet invoker



                    Could you suggest what is going on? I am really stuck and I need the help of experts like yourself.
                    Thanks a lot in advance