6 Replies Latest reply on Mar 18, 2003 9:12 AM by klagesb5

    [jboss 3.0] jndi problem (NamingContextFactory)

    dgadd

      I'm trying to configure jndi in order to do a context lookup. I'm using the following code:

      Properties h = new Properties();
      h.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      h.put(Context.PROVIDER_URL, "localhost:1099");
      h.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      try {
      InitialContext jndiContext = new InitialContext(h);
      } catch (NamingException ne) {
      System.out.println ("NamingException was thrown: " + ne);
      }

      When I compile the class and try and run it from jboss 3.0, I get the following error. Any idea why?

      NamingException was thrown: javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
      Exception in thread "main" java.lang.ClassCastException
      at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
      at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
      at com.gaddzeit.zzexercises.HelloClient.getPortableHomeInterface(HelloClient.java:65)
      at com.gaddzeit.zzexercises.HelloClient.setupEJBClient(HelloClient.java:30)
      at com.gaddzeit.zzexercises.HelloClient.main(HelloClient.java:23)

        • 1. Re: [jboss 3.0] jndi problem (NamingContextFactory)
          dgadd

          FURTHER on this:

          I'm running my tests from unix command line, and I think it may be my classpath setting. It seems to work fine in jBoss 2.4.4, just not in jBoss 3.0.0 (where I need it to work).

          Here's my procedure:
          1) Start jBoss2.4.4
          2) In the client window, set the following classpath environment:
          setenv CLASSPATH "/System/Library/Frameworks/JavaVM.framework/Versions/1.3/Classes/classes.jar:/usr/local/jakarta-tomcat-4.0.3/common/lib/servlet.jar:/usr/local/jakarta-tomcat-4.0.3/webapps/ROOT/WEB-INF/bin/mm.mysql-2.0.11-bin.jar:/usr/local/jakarta-tomcat-4.0.3/webapps/ROOT/WEB-INF/classes:/usr/local/jboss2/jboss/lib/ext/jboss-j2ee.jar:/usr/local/jboss2/jboss/client/jboss-client.jar"
          3) Run the client as follows:
          java com.gaddzeit.zzexercises.CountClient

          This works fine.

          I then quit jBoss 2.4.4. And then:

          1) Start jBoss3.0.0beta
          2) In the client window, set the following classpath environment:
          setenv CLASSPATH "/System/Library/Frameworks/JavaVM.framework/Versions/1.3/Classes/classes.jar:/usr/local/jakarta-tomcat-4.0.3/common/lib/servlet.jar:/usr/local/jakarta-tomcat-4.0.3/webapps/ROOT/WEB-INF/bin/mm.mysql-2.0.11-bin.jar:/usr/local/jakarta-tomcat-4.0.3/webapps/ROOT/WEB-INF/classes:/usr/local/jboss-3.0.0beta/lib/ext/jboss-j2ee.jar:/usr/local/jboss-3.0.0beta/client/jboss-client.jar"
          3) Run the client as follows:
          java com.gaddzeit.zzexercises.CountClient

          In this case, I get the NamingException error as stated in the first message.

          So--why does the same client connect to jndi on jBoss2.4.4, but not on jBoss 3.0.0? Does anybody see anything wrong with my classpath settings?

          Thanks,
          David Gadd

          • 2. Re: [jboss 3.0] jndi problem (NamingContextFactory)
            vkie001

            Make sure the compiler can see "org.jnp.interfaces.NamingContextFactory", you should have this jar in your classpath when compile. This is one of the jboss jnpclient.jar locate in jboss/client directory.

            • 3. Re: [jboss 3.0] jndi problem (NamingContextFactory)
              ezaydens

              I have a very similar problem. I wrote a small JMS client that sends msgs to pub/sub topic. I am trying to run it from the command line. I have compiled it with the classpath that included jnp-client.jar which contains NamingContextFactory. Still errors out. Any other ideas would be greatly appreciated...

              • 4. Re: [jboss 3.0] jndi problem (NamingContextFactory)

                Putting the JNDI properties in the code is not the standard way to do this in J2EE. It may be that JBoss has become a little stricter in what it will allow between 2.4 and 3.0.

                The standard method is ALWAYS to get the initial context using the default constructor. Then, in the module's class path (i.e. under WEB-INF/classes if this is a web module, or at the root of the classes if this is an EJB module) create a jndi.properties file with the properties you need defined there. So it should look like:

                java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                java.naming.provider.url=localhost
                java.naming.factory.url.pkgs=org.jboss.interfaces

                I'd be interested to know if this fixes the problem.

                • 5. Re: [jboss 3.0] jndi problem (NamingContextFactory)
                  ezaydens

                  Nope, that did not do it (at least for me). What eliminated a problem was switching from jdk1.4.1_01 to 1.3.1_06 version. Something is not quite working correctly in the Sun's new release. Uf, was starting to get desperate there... :)

                  • 6. Re: [jboss 3.0] jndi problem (NamingContextFactory)
                    klagesb5

                    I have this problem and I am actually using jdk1.3.1_06! Anyone any other ideas?