6 Replies Latest reply on Jan 18, 2012 10:48 PM by jaikiran

    Remote EJB

    jbossadmin_007

      Hello,

       

      I am currently attempting to learn EJBs (with JBoss 5.1), however I am having some trouble with classpath (I guess). I have a simple EJB client and server jar (From the EJB 3 in Action book code samples [1]). I deploy the server jar to JBoss and call it from the client outside JBoss (remote) via the following command:

       

      java -jar myEjbClient.jar -classpath /home/jdoe/Desktop/jboss-5.1.0.GA/lib/*.jar /home/jdoe/Desktop/jboss-5.1.0.GA/common/lib/*.jar /home/jdoe/Desktop/jboss-5.1.0.GA/server/default/deployers/ejb3.deployer/*.jar /home/jdoe/Desktop/jboss-5.1.0.GA/server/default/deployers/jboss-aop-jboss5.deployer/*.jar /home/jdoe/Desktop/jboss-5.1.0.GA/client/*.jar

       

      As you can see, I place pretty much everthing on the classpath, but I keep running into:

       

      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]

                at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)

                at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)

                at javax.naming.InitialContext.init(InitialContext.java:240)

                at javax.naming.InitialContext.<init>(InitialContext.java:214)

                at com.ejb3inaction.actionbazaar.client.HelloUserClient.main(HelloUserClient.java:20)

      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory

                at java.net.URLClassLoader$1.run(URLClassLoader.java:217)

                at java.security.AccessController.doPrivileged(Native Method)

                at java.net.URLClassLoader.findClass(URLClassLoader.java:205)

                at java.lang.ClassLoader.loadClass(ClassLoader.java:321)

                at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)

                at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

                at java.lang.Class.forName0(Native Method)

                at java.lang.Class.forName(Class.java:264)

                at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:63)

                at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)

                ... 4 more

       

       

      How am I getting  "java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory" when jnpserver.jar (which contains this class) is on the classpath (common/lib directory)

       

      *FYI, I didnt use jndi.properties (in client jar), I used the following instead: 

        Hashtable<String,String> env = new Hashtable<String,String>();

                                    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                                    env.put(Context.URL_PKG_PREFIXES,"jboss.naming:org.jnp.interfaces");

                                    env.put(Context.PROVIDER_URL, "localhost:1099");

                                    InitialContext context = new InitialContext(env);

       

      *FYI, I have also specified an entry point in MANIFEST.MF in the client jar.

       

      I attached both server and client jar; they also contain the source (from the book).

       

      Thanks for your help

       

      -jbossadmin_007

       

       

       

      [1]http://www.manning.com/panda/

        • 1. Re: Remote EJB
          jaikiran

          The *.jar syntax won't work. All you need is to add the JBOSS_HOME/client/jbossall-client.jar to the client classpath.

          • 2. Re: Remote EJB
            jbossadmin_007

            Hello jaikiran,

             

            I tried the following:

             

            java -jar myEjbClient.jar -cp /home/jdoe/Desktop/JBoss/jboss-5.1.0.GA/client/jbossall-client.jar

             

            and

             

            java -jar myEjbClient.jar -classpath /home/jdoe/Desktop/JBoss/jboss-5.1.0.GA/client/jbossall-client.jar

             

            Im still getting

             

            javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]

                      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)

                      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)

                      at javax.naming.InitialContext.init(InitialContext.java:240)

                      at javax.naming.InitialContext.<init>(InitialContext.java:214)

                      at com.ejb3inaction.actionbazaar.client.HelloUserClient.main(HelloUserClient.java:20)

            Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory

                      at java.net.URLClassLoader$1.run(URLClassLoader.java:217)

                      at java.security.AccessController.doPrivileged(Native Method)

                      at java.net.URLClassLoader.findClass(URLClassLoader.java:205)

                      at java.lang.ClassLoader.loadClass(ClassLoader.java:321)

                      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)

                      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

                      at java.lang.Class.forName0(Native Method)

                      at java.lang.Class.forName(Class.java:264)

                      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:63)

                      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)

                      ... 4 more

            • 3. Re: Remote EJB
              jaikiran

              java -jar myEjbClient.jar ...

              The moment you use java -jar, it won't use the classpath specified via the -cp parameter. It will look for the Class-Path attribute in the myEjbClient.jar/META-INF/MANIFEST.MF to setup the classpath. Sorry hadn't paid attention that from your first post. You can try running it as:

               

              java -cp <classpath containing your client class and JBoss jars> <your client classname>

              • 4. Re: Remote EJB
                jbossadmin_007

                Hello,

                 

                Thanks so much for your help. I feel as if I'm making some progress; however, now I have a different exception:

                 

                From the command line, I run the following:

                java -cp /home/jdoe/Desktop/JBoss/jboss-5.1.0.GA/client/jbossall-client.jar:myEjbClient.jar com.ejb3inaction.actionbazaar.client.HelloUserClient

                 

                I now recieve a different output:

                 

                log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).

                log4j:WARN Please initialize the log4j system properly.

                javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]

                          at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1504)

                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:822)

                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)

                          at javax.naming.InitialContext.lookup(InitialContext.java:409)

                          at com.ejb3inaction.actionbazaar.client.HelloUserClient.main(HelloUserClient.java:21)

                Caused by: java.lang.reflect.UndeclaredThrowableException

                          at $Proxy0.createProxyBusiness(Unknown Source)

                          at org.jboss.ejb3.proxy.impl.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)

                          at org.jboss.ejb3.proxy.impl.objectfactory.session.stateless.StatelessSessionProxyObjectFactory.getProxy(StatelessSessionProxyObjectFactory.java:79)

                          at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:158)

                          at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)

                          at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1479)

                          at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1496)

                          ... 4 more

                Caused by: java.lang.ClassNotFoundException: com.ejb3inaction.actionbazaar.buslogic.HelloUser

                          at org.jboss.remoting.serialization.ClassLoaderUtility.loadClass(ClassLoaderUtility.java:103)

                          at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:86)

                          at java.lang.Class.forName0(Native Method)

                          at java.lang.Class.forName(Class.java:264)

                          at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveProxyClass(ObjectInputStreamWithClassLoader.java:253)

                          at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1548)

                          at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1510)

                          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1749)

                          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)

                          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)

                          at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:119)

                          at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1809)

                          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1768)

                          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)

                          at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1963)

                          at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1887)

                          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)

                          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)

                          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)

                          at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObjectVersion2_2(JavaSerializationManager.java:238)

                          at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:138)

                          at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:123)

                          at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedRead(MicroSocketClientInvoker.java:1220)

                          at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:850)

                          at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:165)

                          at org.jboss.remoting.Client.invoke(Client.java:1724)

                          at org.jboss.remoting.Client.invoke(Client.java:629)

                          at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)

                          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                          at org.jboss.ejb3.proxy.impl.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:72)

                          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                          at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

                          at $Proxy0.createProxyBusiness(Unknown Source)

                          at org.jboss.ejb3.proxy.impl.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)

                          at org.jboss.ejb3.proxy.impl.objectfactory.session.stateless.StatelessSessionProxyObjectFactory.getProxy(StatelessSessionProxyObjectFactory.java:79)

                          at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:158)

                          at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)

                          at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1479)

                          at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1496)

                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:822)

                          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)

                          at javax.naming.InitialContext.lookup(InitialContext.java:409)

                          at com.ejb3inaction.actionbazaar.client.HelloUserClient.main(HelloUserClient.java:21)

                          at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)

                          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                          at org.jboss.ejb3.proxy.impl.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:72)

                          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                          at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

                          ... 11 more

                • 5. Re: Remote EJB
                  jbossadmin_007

                  I finally figured it out. With the standalone remote EJB client, you have to also include the my server ejb jars on the classpath as well.

                  • 6. Re: Remote EJB
                    jaikiran

                    Sorry did not notice the earlier reply.

                     

                     

                    Johnathan B. wrote:

                     

                    I finally figured it out. With the standalone remote EJB client, you have to also include the my server ejb jars on the classpath as well.

                    You'll only need the EJB's interfaces (business interfaces, home interfaces if any) and ofcourse whatever class types are being passed and returned from and to the bean. You do not need the EJB implementation class on the client classpath.