7 Replies Latest reply on Sep 22, 2006 3:17 PM by dalingxu

    Please help: Failed to run simple EJB 3.0 Application

    mathias.altmeyer

      Hello.

      I'm trying to deploy a simple EJB 3.0 application within JBoss Application Server (build CVSTag=JBoss_4_0_4_GA date=200605151000). Here is my sample code:

      Remote Interface:


      import java.math.BigDecimal;
      import javax.ejb.Remote;

      @Remote
      public interface Converter {
      public BigDecimal dollarToYen(BigDecimal dollars);

      public BigDecimal yenToEuro(BigDecimal yen);
      }



      Bean class:


      import javax.ejb.Stateless;
      import java.math.BigDecimal;

      @Stateless
      public class ConverterBean implements Converter
      {
      private BigDecimal euroRate = new BigDecimal("0.0070");
      private BigDecimal yenRate = new BigDecimal("112.58");

      public BigDecimal dollarToYen(BigDecimal dollars) {
      BigDecimal result = dollars.multiply(yenRate);

      return result.setScale(2, BigDecimal.ROUND_UP);
      }

      public BigDecimal yenToEuro(BigDecimal yen) {
      BigDecimal result = yen.multiply(euroRate);

      return result.setScale(2, BigDecimal.ROUND_UP);
      }
      }


      Test client:


      import java.math.BigDecimal;
      import javax.ejb.EJB;
      import javax.naming.*;

      public class ConverterClient
      {

      public ConverterClient()
      {
      }

      public static void main(String[] args)
      {
      ConverterClient client = new ConverterClient();
      client.doConversion();
      }

      public void doConversion()
      {
      try {
      InitialContext ctx = new InitialContext();
      Converter converter = (Converter)
      ctx.lookup("converter/ConverterBean/remote");

      BigDecimal param = new BigDecimal("100.00");
      BigDecimal yenAmount = converter.dollarToYen(param);

      System.out.println("$" + param + " is " + yenAmount + " Yen.");

      BigDecimal euroAmount = converter.yenToEuro(yenAmount);
      System.out.println(yenAmount + " Yen is " + euroAmount + " Euro.");

      System.exit(0);
      } catch (Exception ex) {
      System.err.println("Caught an unexpected exception!");
      ex.printStackTrace();
      }
      }
      }


      My JNDI properties file:

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


      My ear archive (named converter.ear) has the following content:
      META-INF/application.xml
      beans.jar

      My beans.jar has the following content:
      Converter.class
      ConverterBean.class

      After deploying the archive JBoss don't has created the context path "converter/ConverterBean/remote"! After compiling and running the test client I get an NameNotFoundException:

      javax.naming.NameNotFoundException: converter not bound

      I thought that I don't need a deployment descriptor anymore. Is my ear archive incorrect? What is my fault? Please help me!

      Thank you! Mathias



        • 1. Re: Please help: Failed to run simple EJB 3.0 Application
          peterj

          I think the JNDI lookup should be:

          ctx.lookup("ConverterBean/remote");

          • 2. Re: Please help: Failed to run simple EJB 3.0 Application
            mathias.altmeyer

            Then, I have the same problem than before.

            javax.naming.NameNotFoundException: ConverterBean not bound
            at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
            at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
            at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
            at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:585)
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
            at sun.rmi.transport.Transport$1.run(Transport.java:153)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
            at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
            at java.lang.Thread.run(Thread.java:595)
            at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
            at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
            at sun.rmi.server.UnicastRef.invoke(Unknown Source)
            at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
            at javax.naming.InitialContext.lookup(Unknown Source)
            at demo.client.ConverterClient.main(RemoteRechnerClient.java:22)

            When I deploy my ear archive the server.log writes these messages:

            17:02:14,140 INFO [EARDeployer] Init J2EE application: file:/C:/Programme/jboss_neu/server/default/deploy/converter.ear
            17:02:14,187 INFO [EARDeployer] Started J2EE application: file:/C:/Programme/jboss_neu/server/default/deploy/converter.ear

            • 3. Re: Please help: Failed to run simple EJB 3.0 Application
              peterj

              What are the contents of your ear file? And the contents of the EJB jar file enclosed within the ear file?

              • 4. Re: Please help: Failed to run simple EJB 3.0 Application
                mathias.altmeyer

                My ear file has the following content:

                /beans.jar
                /META-INF/application.xml

                The beans.jat has the following content:

                /Converter.class
                /ConverterBean.class

                That's all. I don't have an ejb-jar.xml. I thought that I don't need it anymore. Isn't it?

                • 5. Re: Please help: Failed to run simple EJB 3.0 Application
                  peterj

                  Run the jmx-console (in the browser, enter http://localhost:8080/jmx-console). Under the "jboss" heading there will be a "service=JNDIView" link, click on that, and on the resulting page click on the Invoke button beneath the list() method. Post the contents of the resulting page.

                  • 6. Re: Please help: Failed to run simple EJB 3.0 Application
                    mathias.altmeyer

                    Thank you for your help, but I have solved the problem. I have compiled the source code with a old or wrong Java-EE jar. Now, I have compiled it with the Jboss Java-EE jars and now it works.

                    • 7. Re: Please help: Failed to run simple EJB 3.0 Application
                      dalingxu

                       

                      "mathias.altmeyer" wrote:
                      Thank you for your help, but I have solved the problem. I have compiled the source code with a old or wrong Java-EE jar. Now, I have compiled it with the Jboss Java-EE jars and now it works.


                      What do you mean compile it with JBoss java-ee jars? Where are the jars? Could you share more detail that how did you use the JBoss Java-EE jars to compile your code?

                      Thanks