9 Replies Latest reply on Oct 14, 2003 6:37 AM by Darran Lofthouse

    java.lang.ClassNotFoundException: org.jnp.interfaces.NamingC

    eliza Newbie

      Hi,

      I'm using JBoss-3.2.1_Tomcat-4.1.12 & JDK 1.4. While running my client application, I get the following error:

      > java -jar clientapp.jar

      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(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.InitialContext.(Unknown Source)
      ...

      This is supposedly in jnp-client.jar located in jboss's client directory. I already included this file in my clientapp.jar file (including the rest of the jar files in the client directory).

      I searched the archives and found some posts about a possible jboss-tomcat integration problem, so I tried using just jboss-3.2.2 (without tomcat or jetty). but still, i get the same error.


      Here's a portion of my code where I set the environment properties:

      Hashtable env = new Hashtable(11);
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      env.put(Context.PROVIDER_URL, "localhost");

      try {
      InitialContext jndiContext = new InitialContext(env);
      ...

      And the ant build file:












































      Is there anything wrong with my ant build file? I browsed my clientapp.jar and the jboss jar files are indeed inside (but can't browse the jboss jar files)...

      I even tried putting it in my classpath explicitly using the -cp option, but I got the same error:

      >java -cp ".;C:\jboss\client\*.jar" -jar clientapp.jar

      >java -cp ".;C:\jboss\client\jnp-client.jar" -jar clientapp.jar

      >java -cp "C:\jboss\client\jnp-client.jar" -jar

      All these didn't work... Would appreciate any help. Thanks.

      Eliza

        • 1. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
          Jon Barnett Master

          Unfortunately I don't think you are calling it correctly. I don't think you can just bundle the actual JAR into your JAR. You actually have to unpack the contents jnp-client.jar and then pack those contents into your own JAR, preserving the directory structures.

          Also, normally you don't need all the JBoss client JARs. Some of these have the same classes in them, as the intention is to have different bundlings for different application purposes.

          The usual client JAR for JBoss/EJB work purposes is jbossall-client.jar.

          From the command line, you would need to do the following:
          java -cp C:\jboss\client\jbossall-client.jar;clientapp.jar my.object.Main

          You would substitute my.object.Main with the fully qualified name for the class that has your main() method in it.

          That should work - your code looks ok.

          Hope it helps.

          • 2. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
            eliza Newbie

            Thank you! The command works. Then I also unjarred jbossall-client.jar before including it into my jar file. Thanks!

            • 3. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
              demiante Newbie

              Hi people, I'm trying to execute a java standalone client to access a session bean. My code compiles normally
              (javac -classpath /usr/bin/jboss-3.2.2RC2/client/jbossall-client.jar:hellobean.jar hello/client/HelloBeanClient.java)
              but when i execute it, it shows the following Exception.
              $java -classpath /usr/bin/jboss-3.2.2RC2/client/jbossall-client.jar:hellobean.jar hello/client/HelloBeanClient

              java.lang.ClassNotFoundException: org/jnp/interfaces/NamingContextFactory
              at java.lang.Class.forName (Class.java)
              at java.lang.Class.forName (Class.java:44)
              at javax.naming.spi.NamingManager.getInitialContext (NamingManager.java:86)
              at javax.naming.InitialContext.getDefaultInitCtx (InitialContext.java:183)
              at javax.naming.InitialContext.getURLOrDefaultInitCtx (InitialContext.java:218)
              at javax.naming.InitialContext.lookup (InitialContext.java:238)
              at hello.client.HelloBeanClient.main (HelloBeanClient.java:14)

              My class HelloBeanClient:

              package hello.client;

              import javax.rmi.*;
              import javax.naming.*;
              import javax.ejb.*;
              import hello.*;

              public class HelloBeanClient {
              public static void main(String[] args) throws Exception {
              System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
              System.setProperty("java.naming.provider.url", "jnp://sartre:1099");
              System.setProperty("java.naming.factory.url.pkgs", "org.jnp.interfaces");
              InitialContext ctx = new InitialContext();
              Object ref = ctx.lookup("ejb/HelloBean");
              HelloBeanHome home = (HelloBeanHome) PortableRemoteObject.narrow(ref, HelloBeanHome.class);
              HelloBean hello = home.create();
              System.out.println(hello.sayHello());
              }
              }

              S.O: Debian GNU/Linux
              JbossDist: jboss-3.2.2RC2

              • 4. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                Jon Barnett Master

                Your java.naming.factory.url.pkgs should usually be "org.jboss.naming:org.jnp.interfaces". That is most likely the issue.

                Otherwise, check that jbossall-client.jar does contain the specified class. It should be there.

                • 5. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                  demiante Newbie

                  As you can see in my previous message I did it! I put the jar jbossall-client.jar in my classpath but now this work only when i put the classpath in the command line . I still dont know why it not find the org.jnp.interfaces.NamingContextFactory in jbossall-client.jar. The class is there! I've tried other jars too, but again... the same error.

                  In this meanwhile i'm setting the classpath in the java command line.

                  • 6. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                    demiante Newbie

                    By the way, i'm setting my classpath in the file /etc/bash.bashrc like this:


                    CLASSPATH=/usr/local/java/lib/tools.jar:/usr/local/jboss-3.2.2RC2/server/default/lib/javax.servlet.jar:/usr/local/jboss-3.2.2RC2/server/default/lib/jboss-j2ee.jar:/usr/local/jboss-3.2RC2/client/jbossall-client.jar:.
                    export CLASSPATH


                    thanxs!

                    • 7. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                      Darran Lofthouse Master

                      Have you checked that the classpath is definately being exported and is available in the shell that you are using to execute the client?

                      • 8. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                        demiante Newbie

                        Yes. I'm wondering if this is a jvm problem or a jar problem.
                        Whatever... it's weird.

                        • 9. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                          Darran Lofthouse Master

                          Did you copy the following from the bash.bashrc file to post on here?

                          CLASSPATH=/usr/local/java/lib/tools.jar:/usr/local/jboss-3.2.2RC2/server/default/lib/javax.servlet.jar:/usr/local/jboss-3.2.2RC2/server/default/lib/jboss-j2ee.jar:/usr/local/jboss-3.2RC2/client/jbossall-client.jar:.
                          export CLASSPATH


                          If you did you might have a .2 missing


                          CLASSPATH=/usr/local/java/lib/tools.jar:/usr/local/jboss-3.2.2RC2/server/default/lib/javax.servlet.jar:/usr/local/jboss-3.2.2RC2/server/default/lib/jboss-j2ee.jar:/usr/local/jboss-3.2.2RC2/client/jbossall-client.jar:.
                          export CLASSPATH