5 Replies Latest reply on Jan 17, 2011 11:56 AM by meenarajani

    newbie question: ejb3 tutorial examples

    ntk

      Hello community,

      I'm new to JBoss and the javaEE environment, and after playing around with the tutorials I have come across a problem with the java naming service (simple problem probably but still one I have found hard to overcome)

       

      What I did:

      1. I took the "Stateless" tutorial source code and created a .jar from it (without the Client.java).

      2. I deployed the new .jar in my JBoss AS distribution, which is the latest JBoss 5 release. Restarted JBoss.

      3. I checked if it is deployed correctly on the JBoss admin console.

      4. I modified the Client.java the following way ( the underlined code is what I added ).

       

      package org.jboss.tutorial.stateless.client;
      import java.util.Hashtable;
      import org.jboss.tutorial.stateless.bean.Calculator;
      import org.jboss.tutorial.stateless.bean.CalculatorRemote;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      public class Client
      {
         public static void main(String[] args) throws Exception
         {
            Hashtable properties = new Hashtable();
            properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
            properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
            properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
            InitialContext ctx = new InitialContext(properties);
            Calculator calculator = (Calculator) ctx.lookup("CalculatorBean/remote");
            System.out.println("1 + 1 = " + calculator.add(1, 1));
            System.out.println("1 - 1 = " + calculator.subtract(1, 1));
         }
      }

       

      .... and I received the following exception:

       

      Exception in thread "main" 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(Unknown Source)

      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)

      at javax.naming.InitialContext.init(Unknown Source)

      at javax.naming.InitialContext.<init>(Unknown Source)

      at org.jboss.tutorial.stateless.client.Client.main(Client.java:41)

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

      at java.net.URLClassLoader$1.run(Unknown Source)

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

      at java.net.URLClassLoader.findClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

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

      at java.lang.Class.forName(Unknown Source)

      at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)

      ... 5 more

       

      What am I doing wrong?

        • 1. Re: newbie question: ejb3 tutorial examples
          ntk

          Solved. Just had to add jnp-client.jar to the Client project to make it work.

          • 2. Re: newbie question: ejb3 tutorial examples
            meenarajani

            Hi

             

            I am getting the same error with the same example. How you added add jnp-client.jar . I am using  I am using Elipse Helios and Jboss 6. I creted a java project with exisiting build file.

            The error stack is

             

            Exception in thread "main" 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
                at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
                at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
                at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
                at javax.naming.InitialContext.lookup(InitialContext.java:392)
                at org.jboss.tutorial.stateless.client.Client.main(Client.java:34)

             

            Can you please reply in detail as I am stucked with eclipse and Jboss for more than 3 weeks.

             

            Thanks

            • 3. Re: newbie question: ejb3 tutorial examples
              wolfgangknauf

              Hi,

               

              do you use a "plain" eclipse or do you use Eclipse WebTools Platform plugin or JBoss Tools plugin? Both plugins make it possible to start a Java client application without having to struggle with JAR includes.

               

              If you want to start the client by using a batch file, you will have to include probably all of the JARs in "jboss-6.0.0.Final\client\" in your classpath.

              With a lot of "try and error", you can reduce this to a set of "really" required JARs, but there is always the chance the later a "ClassNotFoundException" will be thrown.

               

              Hope this helps

               

              Wolfgang

              • 4. Re: newbie question: ejb3 tutorial examples
                meenarajani

                Thanks Wolfgang, it worked, however I was getting casting error later, but resolved it by adding Jbossall-client.jar.

                 

                However I am getting same error while runing the shopingcart example, which is an entity example.I have included both jnp-client and jbossall-client in my library Do you have any clue?

                 

                Thanks again

                 

                Meena

                • 5. newbie question: ejb3 tutorial examples
                  meenarajani

                  After fixing PostgresDS.xml file and creating database before deploying an application solved the problem.

                   

                  Many Thanks for the help

                   

                  Meena Rajani