3 Replies Latest reply on Aug 24, 2003 9:42 AM by Vishal Sharma

    How to naming EJB in test client?

    Jeff Newbie

      I wrote a simple session bean. And packed class files with ejb-jar.xml and jboss.xml into a single HelloWorld.jar. I succeeded in deploying this EJB-JAR.
      However, when I test it in a standalone client, "NoInitialContextException" occurs.

      Here is my code.

      // ejb-jar.xml

      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      <enterprise-beans>

      <ejb-name>Hello</ejb-name>
      examples.HelloHome
      examples.Hello
      <local-home>examples.HelloLocalHome</local-home>
      examples.HelloLocal
      <ejb-class>examples.HelloBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>

      </enterprise-beans>
      </ejb-jar>

      // jboss.xml
      <?xml version="1.0" encoding="UTF-8"?>

      <enterprise-beans>

      <ejb-name>Hello</ejb-name>
      <jndi-name>HelloWorld/Hello</jndi-name>

      </enterprise-beans>


      // code in client
      InitialContext ctx = new InitialContext();
      Object obj = ctx.lookup("HelloWorld/Hello");

      When the app reaches here, the exception is:

      javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

        • 1. Re: How to naming EJB in test client?
          Adrian Brock Master

          Add a jndi.properties to your classpath

          Regards,
          Adrian

          • 2. Re: How to naming EJB in test client?
            Jeff Newbie

            I did so and failed again.

            In my "jndi.properties":
            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            java.naming.provider.url=localhost:1099
            java.naming.factory.url.pkgs=org.jboss.namingrg.jnp.interfaces

            Client code is listed below:
            Properties props = System.getProperties();
            InitialContext ctx = new InitialContext(props);
            Object obj = ctx.lookup("Hello");

            Here is the exception message.
            javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
            NamingException
            at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
            at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
            at javax.naming.InitialContext.init(InitialContext.java:219)
            at javax.naming.InitialContext.(InitialContext.java:195)
            at client.HelloClient.main(HelloClient.java:44)
            Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
            at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:219)
            at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
            at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
            ... 4 more

            • 3. Re: How to naming EJB in test client?
              Vishal Sharma Expert

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


              This is what u need, I hope this helps.
              Cheers.....
              Vishal