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();
      }
      }
      }