12 Replies Latest reply on Jan 15, 2003 12:12 PM by Bouassida

    HelloWorld Example : Newbie need help

    Paul Newbie

      Hi there,

      I am newbie in JBoss and EJB. I have tried the following simple HelloWorld EJB on my machine. However, I get the following error when I try to run it. I apolgies for the pasting of error code here, I really need some guidance. Could someone tell me where did I go wrong and where should I change? Sorry I wanted to attach my source code
      but apparently the attachment function does not work.

      Thank you very much

      1. Test 1 (Method from MasteringEJB2)
      -------------------------------------

      This is the error when i used the following for my client code.
      ==> Properties prop = System.getProperties();

      javax.naming.CommunicationException: Can't find SerialContextProvider
      at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.java:63)
      at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:120)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at test.HelloWorldClient.main(HelloWorldClient.java:22)

      2. Test 2 (Method from JBoss 3 Step by Step)
      --------------------------------------------
      This is the error when i used the following for my client code.
      ==> Hashtable prop = new Hashtable();
      ==> prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      ==> prop.put(Context.PROVIDER_URL, "localhost:1099");
      ==> prop.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
      aces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException:
      org.jnp.interfaces.NamingContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
      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)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:207)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
      at javax.naming.InitialContext.init(InitialContext.java:219)
      at javax.naming.InitialContext.(InitialContext.java:195)
      at test.HelloWorldClient.main(HelloWorldClient.java:23)

      Client code
      ===========

      package test;

      import javax.naming.Context;
      import javax.naming.InitialContext;
      import java.util.Hashtable;
      import java.util.Properties;

      public class HelloWorldClient
      {
      public static void main(String[] args)
      {
      // Test 1
      // Properties prop = System.getProperties();

      // Test 2
      Hashtable prop = new Hashtable();
      prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      prop.put(Context.PROVIDER_URL, "localhost:1099");
      prop.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

      try
      {
      Context ctx = new InitialContext(prop);
      Object obj = ctx.lookup("HelloWorld");
      HelloWorldHome home = (HelloWorldHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloWorldHome.class);
      HelloWorld helloWorld = home.create();
      System.out.println(helloWorld.hello());
      helloWorld.remove();
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }
      }
      }

        • 1. Re: HelloWorld Example : Newbie need help
          Greg Turner Apprentice

          context properties should be like this:

          HashTable prop = new HashTable();
          prop.put ("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
          prop.put ("java.naming.provider.url","jnp://localhost:1099");
          prop.put ("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");

          • 2. Re: HelloWorld Example : Newbie need help
            Paul Newbie

            Hi sgturner,

            I have changed the code you given above. However it
            still gives the same error message as the one in
            Test 2. Any other hints?

            Sincere thanks.

            • 3. Re: HelloWorld Example : Newbie need help
              Weber Oliveira Newbie

              hi,

              couldn't you post the rest of the code (along with the descriptors)?

              Weber.

              • 4. Re: HelloWorld Example : Newbie need help
                Weber Oliveira Newbie

                hi,

                couldn't you post the rest of the code (along with the descriptors)?

                cya,
                Weber.

                • 5. Re: HelloWorld Example : Newbie need help
                  Paul Newbie

                  Hi Weber,

                  this are the source file. Please help a new bie.

                  Could you kindly advise me also what should the setting be for the workers.properties file for the following lines
                  worker.ajp12.host=<<YOUR SERVERS IP ADDRESS >>
                  worker.ajp13.host=<<YOUR SERVERS IP ADDRESS >>

                  If I am running Tomcat/JBoss/Apache all on the same machine. My machine name is myComp.Is it
                  worker.ajp12.host=myComp
                  worker.ajp13.host=myComp
                  I am confused about my server ip since I am running on my
                  machine only.

                  Thanks a lot. Really appreciate your help.

                  • 6. Re: HelloWorld Example : Newbie need help
                    Weber Oliveira Newbie

                    hi again Paul (that is your name, right?),

                    i know what's going on. I've downloaded your code and its running smoothly here. The problem is in your classpath. It *must* include some of the client jars which come with the distribution. Those jars contain, for example, the org.jnp.interfaces.NamingContextFactory class your trying to use. For such a simple test as this one, it wouldn't be necessary to include all the client jars in the class path (as a matter of fact, i think the minimum set would only include: jboss-common-client.jar, jnp-client.jar, jboss-client.jar, jbosssx-client.jar and possibly log4j.jar)

                    I don't know if your using Linux, but in case you are, you could try do do the following in the bash prompt (that's what i did):

                    $ cd $JBOSS_HOME/lib; for FILE in *.jar; do export \ CLASSPATH=$CLASSPATH:`pwd`/$FILE; done; cd -

                    It was enough for me to make it work here.

                    PS: regarding the doubt about the workers.properties file, i couldn't quite understand what is the problem.

                    Hope it helps,
                    Weber.

                    • 7. Re: HelloWorld Example : Newbie need help
                      Paul Newbie

                      Thanks Weber,

                      That indeed was my error. Couldnt' express how
                      happy I was to see my first hello world example
                      to work!

                      See you
                      Paul

                      • 8. Re: HelloWorld Example : Newbie need help
                        Bouassida Newbie

                        Hi everyone

                        I'm also a new bie and I'm trying to deploy a simple EJB. I've installed jboss-3.0.4_tomcat-4.1.12. I've run it and it is OK. Then, I've develop my EJB ; I've also got my 3 classes and my jar file. But how can I deploy it ? I mean, where should I put all my files to make it run on JBOss ?
                        Same question for my Client file ?

                        Thanks for your help.

                        Nadia "Another new Bie"

                        • 9. Re: HelloWorld Example : Newbie need help
                          Alex Shneyderman Newbie

                          deploy directory of jboss server.

                          in directory
                          $JBOSS_HOME/server
                          there are three (distribution) subdirectories
                          minimal
                          all
                          default

                          each one of them will have deploy directory. Just copy your ejb-jar or war or ear or sar files over there and Jboss will deploy them autmagically.

                          • 10. Re: HelloWorld Example : Newbie need help
                            Alex Shneyderman Newbie

                            I meant in one of the default/all/minimal depending on which config you are running.

                            If you run Jboss with the command run.sh/run.bat
                            default config is used. otherwise whatever you specified in -c option for the above command is your current config.

                            • 11. Re: HelloWorld Example : Newbie need help
                              Bouassida Newbie

                              Hi,

                              Ok, now, I manage to deploy my example on JBoss. I've add a file : jboss.xml in the Meta-inf directorie. I've put my client code in the directorie client and when i try to run it I've got an error :


                              Can someone help me too to make my first hello word run ...

                              Thanks ...

                              Nadia

                              • 12. Re: HelloWorld Example : Newbie need help
                                Bouassida Newbie

                                ps : all my files : hello word bean + xml files + my classpath + a capture of my error.

                                Thanks to help me ...

                                Nadia