14 Replies Latest reply on May 8, 2008 5:06 AM by Thomas Chang

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

    Thomas Chang Apprentice

      Hi all,

      I've wrote a small ejb3 stateless session bean program and have deploy the JAR to the server (JBoss 4.2.1.GA).

      Then I wrote a test client and try to access the bean I got exception as follow:
      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:242)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
      ... 4 more

      Someone can help me?

        • 1. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
          jaikiran pai Master

          You will have to place the jbossall-client.jar file (which you can find in %JBOSS_HOME%\client folder) in the classpath of the client.

          • 2. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
            Thomas Chang Apprentice

            Thanks for the info. I can go astep further. But now I get another exception as follow, seems it is a problem of compatability:

            Caused by: java.io.InvalidClassException: org.jboss.ejb3.LocalProxy; local class incompatible: stream classdesc serialVersionUID = -6521545933800264895, local class serialVersionUID = -7089389644057030711
            at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:546)
            at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1552)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
            at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1552)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
            at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1908)
            at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1832)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1719)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
            at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
            at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:654)
            ... 3 more

            • 3. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
              jaikiran pai Master

              Are you sure you copied the correct version of the jar file? The jbossall-client.jar file should be the same as the one on the server. And do you have any other JBoss jar files in the client classpath?

              • 4. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                Thomas Chang Apprentice

                The exception of compatabability obve is resolved.
                Client
                Now I got another exception:
                Exception in thread "main" javax.ejb.EJBException: Invalid invocation of local interface (null container)
                at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:77)
                at $Proxy0.test(Unknown Source)
                at com.wei.chen.TestClient.main(TestClient.java:27)

                And here is my code of "TestClient.java":
                ...
                Context context;
                try {
                context = new InitialContext();
                MyBeanLocal beanLocal = (MyBeanLocal) context.lookup(TestMyBean.LocalJNDIName);
                beanLocal.test("Wei Chen");
                } catch (NamingException e) {
                e.printStackTrace();
                }
                ...

                • 5. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                  Thomas Chang Apprentice

                  Here is all my codes:

                  MyBeanLocal.java
                  ****************
                  @Local
                  public interface MyBeanLocal {
                  public String test(String text);
                  }

                  TestMyBean.java
                  ***************
                  @Stateless
                  public class TestMyBean implements MyBeanLocal {

                  public static final String LocalJNDIName = TestMyBean.class.getSimpleName() + "/local";

                  public String test(String text) {
                  return "Hello, " + text;
                  }

                  }

                  TestClient.java
                  *************
                  public class TestClient {
                  public static void main(String[] args) {

                  Context context;
                  try {
                  context = new InitialContext();
                  MyBeanLocal beanLocal = (MyBeanLocal) context
                  .lookup(TestMyBean.LocalJNDIName);
                  beanLocal.test("Wei Chen");
                  } catch (NamingException e) {
                  e.printStackTrace();
                  }
                  }
                  }

                  jndi.properties
                  *************
                  java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                  java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
                  java.naming.provider.url=localhost:1099

                  • 6. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                    jaikiran pai Master

                    You cannot use an Local interface from a remote client (the standalone java client, running in its own JVM). You will require a remote interface for the bean. Use an interface with @Remote.

                    • 7. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                      Thomas Chang Apprentice

                       

                      "jaikiran" wrote:
                      You cannot use an Local interface from a remote client (the standalone java client, running in its own JVM). You will require a remote interface for the bean. Use an interface with @Remote.


                      You are right. Now I change the Local to remote as follow:

                      MyBeanLocal.java
                      ****************
                      @Remote
                      public interface MyBeanLocal {
                      public String test(String text);
                      }

                      TestMyBean.java
                      ***************
                      @Stateless
                      public class TestMyBean implements MyBeanLocal {

                      public static final String LocalJNDIName = TestMyBean.class.getSimpleName() + "/remote";

                      public String test(String text) {
                      return "Hello, " + text;
                      }

                      But I get a new exception as follow:
                      Caused by: javax.naming.NameNotFoundException: remote not bound
                      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
                      at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
                      at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
                      at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
                      at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                      at java.lang.reflect.Method.invoke(Method.java:585)
                      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
                      at sun.rmi.transport.Transport$1.run(Transport.java:153)
                      at java.security.AccessController.doPrivileged(Native Method)
                      at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
                      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
                      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
                      at java.lang.Thread.run(Thread.java:595)
                      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
                      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
                      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
                      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
                      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
                      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:589)
                      at javax.naming.InitialContext.lookup(InitialContext.java:351)
                      at com.wei.chen.TestClient.main(TestClient.java:26)



                      • 8. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                        jaikiran pai Master

                        You probably are not using the correct jndi-name while doing the lookup in the client. Use the JNDIView http://wiki.jboss.org/wiki/DisplayTheJNDITreeWithTheJMXConsole to list the contents of the jndi-tree and see what's the jndi-name for your bean.

                        Alternately, you can annotate the bean to use a jndi-name of your choice and use that jndi-name in your client lookup.

                        @Stateless
                        @RemoteBinding(jndiBinding = "MyJNDIName")
                        public class TestMyBean implements MyBeanLocal {


                        Client code:

                        MyBeanLocal bean = (MyBeanLocal) ctx.lookup("MyJNDIName");


                        • 9. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                          Thomas Chang Apprentice

                          Here is the list. Where can I find the correct jndi-name?

                          Besides, I try your alternativ but I get Exception of "MyJNDIName not bound".

                          Global JNDI Namespace
                          +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair)
                          +- jmx (class: org.jnp.interfaces.NamingContext)
                          | +- invoker (class: org.jnp.interfaces.NamingContext)
                          | | +- RMIAdaptor (proxy: $Proxy48 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
                          | +- rmi (class: org.jnp.interfaces.NamingContext)
                          | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
                          +- TestMyBean (class: org.jnp.interfaces.NamingContext)
                          | +- local (proxy: $Proxy65 implements interface com.wei.chen.MyBeanLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
                          +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
                          +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
                          +- UserTransactionSessionFactory (proxy: $Proxy14 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
                          +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
                          +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
                          +- TransactionSynchronizationRegistry (class: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple)
                          +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
                          +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
                          +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
                          +- queue (class: org.jnp.interfaces.NamingContext)
                          | +- A (class: org.jboss.mq.SpyQueue)
                          | +- testQueue (class: org.jboss.mq.SpyQueue)
                          | +- ex (class: org.jboss.mq.SpyQueue)
                          | +- DLQ (class: org.jboss.mq.SpyQueue)
                          | +- D (class: org.jboss.mq.SpyQueue)
                          | +- C (class: org.jboss.mq.SpyQueue)
                          | +- B (class: org.jboss.mq.SpyQueue)
                          +- topic (class: org.jnp.interfaces.NamingContext)
                          | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
                          | +- testTopic (class: org.jboss.mq.SpyTopic)
                          | +- securedTopic (class: org.jboss.mq.SpyTopic)
                          +- console (class: org.jnp.interfaces.NamingContext)
                          | +- PluginManager (proxy: $Proxy49 implements interface org.jboss.console.manager.PluginManagerMBean)
                          +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
                          +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
                          +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
                          +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair)
                          +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)

                          • 10. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                            jaikiran pai Master

                             

                            +- TestMyBean (class: org.jnp.interfaces.NamingContext)
                            | +- local (proxy: $Proxy65 implements interface com.wei.chen.MyBeanLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)


                            Here's the jndi-name. You should use "TestMyBean/local" in the client while doing the lookup. By the way, are you sure that your changes to the beans and its interfaces are being picked up? I would have expected this jndi-name to look like TestMyBean/remote when using @Remote.


                            • 11. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                              Thomas Chang Apprentice

                              I see in the list folowings:

                              +- TestMyBean (class: org.jnp.interfaces.NamingContext)
                              | +- local (proxy: $Proxy65 implements interface com.wei.chen.MyBeanLocal,interface org.jboss.ejb3.JBossProxy,interface
                              


                              It is still local though I've changed to remote in my codes.

                              How can I overcome it?

                              • 12. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                                Thomas Chang Apprentice

                                 

                                "jaikiran" wrote:
                                +- TestMyBean (class: org.jnp.interfaces.NamingContext)
                                | +- local (proxy: $Proxy65 implements interface com.wei.chen.MyBeanLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)


                                By the way, are you sure that your changes to the beans and its interfaces are being picked up? I would have expected this jndi-name to look like TestMyBean/remote when using @Remote.


                                That's what I wondering as well. I delete the JAR and start the server again but I still see the local-jndi there. Strange.

                                • 13. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam
                                  jaikiran pai Master

                                   

                                  "thomas2008ch" wrote:


                                  How can I overcome it?


                                  Make sure that your changes to the bean and its interfaces are being picked up. Compile those classes, recreate the jar and then clean the existing jar from the JBoss deploy folder and deploy this new jar file.