5 Replies Latest reply on Sep 26, 2002 7:17 AM by Adrian Brock

    Mastering EJBs-- Stateless Session Example -- Running the Cl

    Mark Newbie

      How do you run the client in this book for the Stateless Session Example???

        • 1. Re: Mastering EJBs-- Stateless Session Example -- Running th
          Mark Newbie

          Here is my client code:


          package com.msebik.ejb.session.helloworld;

          import javax.ejb.*;
          import javax.naming.*;
          import java.rmi.*;
          import java.util.Properties;

          public class HelloClient {

          public static void main(String[] args) {
          try {
          Properties props = System.getProperties();
          Context ctx = new InitialContext(props);
          HelloHome home=(HelloHome) ctx.lookup("HelloHome");
          Hello hello=home.create();
          System.out.println(hello.hello());
          hello.remove();
          }catch (Exception e) {
          e.printStackTrace();
          }

          }
          }

          -----------
          Where do I put the client?? And how do I run it??

          • 2. Re: Mastering EJBs-- Stateless Session Example -- Running th
            Udontcare Newbie

            Just use the classical 'java' command-line while jboss is running and EJB is deployed.

            Be sure that you import all necessary classes or packages with the options of the 'java' command. You can also use an xml file which will be used by Apache Ant. I think it's a bit easier this way, and you don't have to rewrite your command each time you want to run the client.

            Gandalf the White

            • 3. Re: Mastering EJBs-- Stateless Session Example -- Running th
              Mark Newbie

              thanks for helping ...
              However I get this error when i "java HelloClient"

              C:\ejb_dev\mast_ejb_examp\WEB-INF\classes\com\msebik\ejb\session\helloworld>java
              HelloClient
              Exception in thread "main" java.lang.NoClassDefFoundError: HelloClient (wrong na
              me: com/msebik/ejb/session/helloworld/HelloClient)
              at java.lang.ClassLoader.defineClass0(Native Method)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
              at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
              3)
              at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
              at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
              at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)

              -----------

              Please write back ..thanks in advance

              • 4. Re: Mastering EJBs-- Stateless Session Example -- Running th
                Mark Newbie

                I have made progress. But I still have a little to go.
                I made changes to my client code.
                --------

                import javax.ejb.*;
                import javax.naming.*;
                import javax.rmi.PortableRemoteObject;
                import java.util.Properties;
                import com.msebik.ejb.session.helloworld.*;

                public class HelloClient {

                public static void main(String[] args) {
                System.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
                System.setProperty("java.naming.provider.url", "localhost:1099");
                try {
                // Properties props = System.getProperties();
                // Get a naming context
                InitialContext jndiContext = new InitialContext();
                System.out.println("Got context");

                // Get a reference to the Interest Bean
                Object ref = jndiContext.lookup("hello/Hello");
                System.out.println("Got reference");

                // Get a reference from this to the Bean's Home interface
                HelloHome home = (HelloHome)PortableRemoteObject.narrow(ref, HelloHome.class);
                System.out.println("Cast HelloHome");

                //Context ctx = new InitialContext(props);
                //HelloHome home=(HelloHome) ctx.lookup("hello/Hello");
                Hello hello=home.create();
                System.out.println(hello.hello());
                //hello.remove();
                }catch (Exception e) {
                e.printStackTrace();
                }

                }
                }
                -----
                This is what I get when I run it ( java HelloClient )

                C:\ejb_dev\mast_ejb_examp>java HelloClient
                Got context
                Got reference
                Cast HelloHome
                Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/security/Se
                curityAssociation
                at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:7
                2)
                at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:185)
                at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
                at $Proxy0.create(Unknown Source)
                at HelloClient.main(HelloClient.java:28)

                -----

                Anyone got a clue ???

                • 5. Re: Mastering EJBs-- Stateless Session Example -- Running th
                  Adrian Brock Master

                  You will find that class in
                  client/jbosssx-client.jar

                  Regards,
                  Adrian