8 Replies Latest reply on Oct 19, 2011 3:44 AM by phiboss Branched from an earlier discussion.

    JBoss AS6: Mini (Stateful) EJB 3 Example using JBoss and Eclipse

    phiboss

      Hi

       

      I switched to JBoss 6.1.0. I created a new JBoss 6.1.0-Server Project:

       

      package ch.my.timer.server;

      import javax.ejb.Remote;

       

      @Remote

      public interface MyTimerRemote {

        void  setRemainingSecs(int seconds);

        float getRemainingSecs();

      }

       

      Here the implementation:

       

      import javax.ejb.Stateful;

       

       

      /**

      * Session Bean implementation class MyTimer

      */

      @Stateful(mappedName="/MyTimer")

      public class MyTimer implements MyTimerRemote {

       

          public MyTimer() {

              this.endTimePoint = System.currentTimeMillis();

          }

       

          private long endTimePoint; // timestamp in milliseconds

       

          @Override

          public void setRemainingSecs(int seconds) {

              long millis = seconds * 1000;

              long now    = System.currentTimeMillis();

              this.endTimePoint = now + millis;

          }

       

          @Override

          public float getRemainingSecs() {

              long now  = System.currentTimeMillis();

              long diff = this.endTimePoint - now;

              float secs = (float) (diff / 1000.0);

              return secs;

          }

       

      }

       

      Starting the Server I get the following messages:

       

      14:42:56,224 INFO  [AbstractJBossASServerBase] Server Configuration:

       

          JBOSS_HOME URL: file:/usr/share/jboss-6.1.0.Final/

          Bootstrap: $JBOSS_HOME/server/default/conf/bootstrap.xml

          Common Base: $JBOSS_HOME/common/

          Common Library: $JBOSS_HOME/common/lib/

          Server Name: default

          Server Base: $JBOSS_HOME/server/

          Server Library: $JBOSS_HOME/server/default/lib/

          Server Config: $JBOSS_HOME/server/default/conf/

          Server Home: $JBOSS_HOME/server/default/

          Server Data: $JBOSS_HOME/server/default/data/

          Server Log: $JBOSS_HOME/server/default/log/

          Server Temp: $JBOSS_HOME/server/default/tmp/

       

      14:42:56,229 INFO  [AbstractServer] Starting: JBossAS [6.1.0.Final "Neo"]

      14:43:00,161 INFO  [ServerInfo] Java version: 1.6.0_26,Sun Microsystems Inc.

      14:43:00,164 INFO  [ServerInfo] Java Runtime: Java(TM) SE Runtime Environment (build 1.6.0_26-b03)

      14:43:00,167 INFO  [ServerInfo] Java VM: Java HotSpot(TM) 64-Bit Server VM 20.1-b02,Sun Microsystems Inc.

      14:43:00,168 INFO  [ServerInfo] OS-System: Linux 2.6.38-11-generic,amd64

      14:43:00,168 INFO  [ServerInfo] VM arguments: -Dprogram.name=JBossTools: JBoss 6.x Runtime -Xms256m -Xmx768m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=/usr/share/jboss-6.1.0.Final/lib/endorsed -Djava.library.path=/usr/share/jboss-6.1.0.Final/bin/native -Dlogging.configuration=file:/usr/share/jboss-6.1.0.Final/bin/logging.properties -Dfile.encoding=UTF-8

      14:43:00,327 INFO  [JMXKernel] Legacy JMX core initialized

      14:43:14,514 INFO  [AbstractServerConfig] JBoss Web Services - Stack CXF Server 3.4.1.GA

      14:43:17,049 INFO  [JSFImplManagementDeployer] Initialized 3 JSF configurations: [Mojarra-1.2, MyFaces-2.0, Mojarra-2.0]

      14:43:33,793 WARNING [FileConfigurationParser] AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal

      14:43:34,327 INFO  [JMXConnector] starting JMXConnector on host localhost:1090

      14:43:34,571 INFO  [MailService] Mail Service bound to java:/Mail

      14:43:36,189 INFO  [HornetQServerImpl] live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=/usr/share/jboss-6.1.0.Final/server/default/data/hornetq/journal,bindingsDirectory=/usr/share/jboss-6.1.0.Final/server/default/data/hornetq/bindings,largeMessagesDirectory=/usr/share/jboss-6.1.0.Final/server/default/data/hornetq/largemessages,pagingDirectory=/usr/share/jboss-6.1.0.Final/server/default/data/hornetq/paging)

      14:43:36,192 INFO  [HornetQServerImpl] Waiting to obtain live lock

      14:43:36,372 INFO  [JournalStorageManager] Using NIO Journal

      14:43:36,441 WARNING [HornetQServerImpl] Security risk! It has been detected that the cluster admin user and password have not been changed from the installation default. Please see the HornetQ user guide, cluster chapter, for instructions on how to do this.

      14:43:36,689 INFO  [FileLockNodeManager] Waiting to obtain live lock

      14:43:36,689 INFO  [FileLockNodeManager] Live Server Obtained live lock

      14:43:37,912 INFO  [NettyAcceptor] Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5445 for CORE protocol

      14:43:37,916 INFO  [NettyAcceptor] Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5455 for CORE protocol

      14:43:37,919 INFO  [HornetQServerImpl] Server is now live

      14:43:37,920 INFO  [HornetQServerImpl] HornetQ Server version 2.2.5.Final (HQ_2_2_5_FINAL_AS7, 121) [ae730dd9-f3e9-11e0-86b0-001f3b82ac6b] started

      14:43:38,271 INFO  [WebService] Using RMI server codebase: http://localhost:8083/

      14:43:38,609 INFO  [jbossatx] ARJUNA-32010 JBossTS Recovery Service (tag: JBOSSTS_4_14_0_Final) - JBoss Inc.

      14:43:38,618 INFO  [arjuna] ARJUNA-12324 Start RecoveryActivators

      14:43:38,651 INFO  [arjuna] ARJUNA-12296 ExpiredEntryMonitor running at Tue, 11 Oct 2011 14:43:38

      14:43:38,748 INFO  [arjuna] ARJUNA-12310 Recovery manager listening on endpoint 127.0.0.1:4712

      14:43:38,749 INFO  [arjuna] ARJUNA-12344 RecoveryManagerImple is ready on port 4712

      14:43:38,749 INFO  [jbossatx] ARJUNA-32013 Starting transaction recovery manager

      14:43:38,775 INFO  [arjuna] ARJUNA-12163 Starting service com.arjuna.ats.arjuna.recovery.ActionStatusService on port 4713

      14:43:38,776 INFO  [arjuna] ARJUNA-12337 TransactionStatusManagerItem host: 127.0.0.1 port: 4713

      14:43:38,832 INFO  [arjuna] ARJUNA-12170 TransactionStatusManager started on port 4713 and host 127.0.0.1 with service com.arjuna.ats.arjuna.recovery.ActionStatusService

      14:43:38,952 INFO  [jbossatx] ARJUNA-32017 JBossTS Transaction Service (JTA version - tag: JBOSSTS_4_14_0_Final) - JBoss Inc.

      14:43:39,044 INFO  [arjuna] ARJUNA-12202 registering bean jboss.jta:type=ObjectStore.

      14:43:39,859 INFO  [AprLifecycleListener] The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/share/jboss-6.1.0.Final/bin/native

      14:43:40,291 INFO  [TomcatDeployment] deploy, ctxPath=/invoker

      14:43:40,780 INFO  [ModClusterService] Initializing mod_cluster 1.1.0.Final

      14:43:40,863 INFO  [RARDeployment] Required license terms exist, view vfs:/usr/share/jboss-6.1.0.Final/server/default/deploy/jboss-local-jdbc.rar/META-INF/ra.xml

      14:43:40,884 INFO  [RARDeployment] Required license terms exist, view vfs:/usr/share/jboss-6.1.0.Final/server/default/deploy/jboss-xa-jdbc.rar/META-INF/ra.xml

      14:43:40,897 INFO  [RARDeployment] Required license terms exist, view vfs:/usr/share/jboss-6.1.0.Final/server/default/deploy/jms-ra.rar/META-INF/ra.xml

      14:43:40,924 INFO  [HornetQResourceAdapter] HornetQ resource adaptor started

      14:43:40,948 INFO  [RARDeployment] Required license terms exist, view vfs:/usr/share/jboss-6.1.0.Final/server/default/deploy/mail-ra.rar/META-INF/ra.xml

      14:43:40,968 INFO  [RARDeployment] Required license terms exist, view vfs:/usr/share/jboss-6.1.0.Final/server/default/deploy/quartz-ra.rar/META-INF/ra.xml

      14:43:41,112 INFO  [SimpleThreadPool] Job execution threads will use class loader of thread: Thread-2

      14:43:41,178 INFO  [SchedulerSignalerImpl] Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl

      14:43:41,179 INFO  [QuartzScheduler] Quartz Scheduler v.1.8.3 created.

      14:43:41,182 INFO  [RAMJobStore] RAMJobStore initialized.

      14:43:41,191 INFO  [QuartzScheduler] Scheduler meta-data: Quartz Scheduler (v1.8.3) 'JBossQuartzScheduler' with instanceId 'NON_CLUSTERED'

        Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.

        NOT STARTED.

        Currently in standby mode.

        Number of jobs executed: 0

        Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.

        Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

       

      14:43:41,192 INFO  [StdSchedulerFactory] Quartz scheduler 'JBossQuartzScheduler' initialized from an externally opened InputStream.

      14:43:41,192 INFO  [StdSchedulerFactory] Quartz scheduler version: 1.8.3

      14:43:41,193 INFO  [QuartzScheduler] Scheduler JBossQuartzScheduler_$_NON_CLUSTERED started.

      14:43:41,778 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'

      14:43:42,132 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA'

      14:43:42,248 INFO  [xnio] XNIO Version 2.1.0.CR2

      14:43:42,262 INFO  [nio] XNIO NIO Implementation Version 2.1.0.CR2

      14:43:42,468 INFO  [remoting] JBoss Remoting version 3.1.0.Beta2

      14:43:42,725 INFO  [TomcatDeployment] deploy, ctxPath=/

      14:43:42,758 INFO  [HornetQServerImpl] trying to deploy queue jms.queue.ExpiryQueue

      14:43:42,890 INFO  [HornetQServerImpl] trying to deploy queue jms.queue.DLQ

      14:43:42,924 INFO  [service] Removing bootstrap log handlers

      14:43:43,050 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-localhost%2F127.0.0.1-8080

      14:43:43,061 INFO  [org.apache.coyote.ajp.AjpProtocol] Starting Coyote AJP/1.3 on ajp-localhost%2F127.0.0.1-8009

      14:43:43,062 INFO  [org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.1.0.Final "Neo"] Started in 46s:816ms

       

       

      It does not look as the EJB is deployed.

      Starting the following Client I get the message below:

       

      package ch.my.timer.client;

       

      import java.util.Hashtable;

       

      import javax.naming.Context;

      import javax.naming.InitialContext;

      import javax.naming.NamingException;

       

      import  ch.my.timer.server.*;

       

      public class MyTimerTest {

        public static void main(String[] args) {

           try {

              new MyTimerTest().top();

           } catch (NamingException e) {

              // TODO Auto-generated catch block

              e.printStackTrace();

           }

         }

       

         void top() throws NamingException {

            Hashtable<String, String> env = new Hashtable<String, String>();     

            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");    

            env.put(Context.PROVIDER_URL, "localhost:1099");     

            env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );

            InitialContext ctx = new InitialContext(env);

       

            MyTimerRemote str = (MyTimerRemote) ctx.lookup("/MyTimer");

       

            str.setRemainingSecs(3);

            float rem = str.getRemainingSecs();

            System.out.println("Remaining: " + rem);

         }

      }

       

       

      ... here comes the message, which is obvious:

       

      javax.naming.NameNotFoundException: MyTimer not bound

          at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)

          at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)

              ...

       

       

      What am I missing now?

       

      Nachricht geändert durch Phi GF. Added a "seeparator" between interface and implementation.

        • 1. Re: JBoss AS6: Mini (Stateful) EJB 3 Example using JBoss and Eclipse
          jaikiran

          Multiple things:

           

          1) The logs don't show any of your deployments being deployed. How did you deploy the EJB jar/ear?

          2) Once JBoss AS deploys the EJBs, it will print out (on the console) the JNDI names to which the beans are bound. Use that JNDI name. JBoss AS does not use the "mappedName" attribute of @Stateless as JNDI names.

          • 2. Re: JBoss AS6: Mini (Stateful) EJB 3 Example using JBoss and Eclipse
            phiboss

            [[ 0) There are 2 threads now, why? (I don't realy understand this forum, sorry). Try to answer here only from now on. ]]

             

             

            1): I mark the Eclipse Project as "deployable" using the context menu on the Project (package explorer) and klick on "Mark as Deployable".

             

            2): Its true, Using former EJB, the server always printed the deployed objects. But this is not the case here!

            "mappedName": That was my error. I realy thought wenn marking as "mappedName", JNDI will map it.

             

            Any Ideas how to provide a JNDI Name using EJB 3.0 when not the "mappedName"?

             

            thanks in advance

            • 3. Re: JBoss AS6: Mini (Stateful) EJB 3 Example using JBoss and Eclipse
              jaikiran

              Phi GF wrote:

               

              1): I mark the Eclipse Project as "deployable" using the context menu on the Project (package explorer) and klick on "Mark as Deployable".

               

              I would recommend that for now, don't use an IDE to create the instead. Instead use a build tool like Ant to generate the jar/war/ear and then manually place the deployment in the JBOSS_HOME/server/<servername>/deploy folder to get it deployed. Once we have got that working you can then figure out what the issue is with deployment through IDE.

               

               

              Phi GF wrote:

               

              2): Its true, Using former EJB, the server always printed the deployed objects. But this is not the case here!

              "mappedName": That was my error. I realy thought wenn marking as "mappedName", JNDI will map it.

               

              Any Ideas how to provide a JNDI Name using EJB 3.0 when not the "mappedName"?

               

               

              See this http://docs.jboss.org/ejb3/docs/tutorial/1.0.7/html/JNDI_Bindings.html

              • 4. Re: JBoss AS6: Mini (Stateful) EJB 3 Example using JBoss and Eclipse
                phiboss

                jaikiran pai Thanks for your prompt answer

                 

                1) I don't want to use a build tool (ANT, maven), because I will not work with EJB later on. It is just a single simple "Hello World"-like demonstration of a Stateful EJB-3.0 session bean using Eclipse (must) and JBoss (or glassfish).

                 

                2) I changed (according to http://docs.jboss.org/ejb3/docs/tutorial/1.0.7/html/JNDI_Bindings.html) my "Stateful Bean" in the following way, but it did not help.

                 

                any further Ideas?

                 

                /**

                * Session Bean implementation class MyTimer

                */

                @Stateful

                @RemoteBinding(jndiBinding="custom/remote/MyTimer")

                public class MyTimer implements MyTimerRemote {

                • 5. Re: JBoss AS6: Mini (Stateful) EJB 3 Example using JBoss and Eclipse
                  jaikiran

                  Phi GF wrote:

                   

                   

                   

                  1) I don't want to use a build tool (ANT, maven), because I will not work with EJB later on. It is just a single simple "Hello World"-like demonstration of a Stateful EJB-3.0 session bean using Eclipse (must) and JBoss (or glassfish).

                  I don't use any IDE to deploy my artifacts to JBoss. So I won't be able to help on that. At this point, the real issue is that your jar is not even being deployed. Someone with IDE experience might be able to help you get past that. And once that's done, it won't take long to use the right jndi name ot do the lookup.

                  • 6. Re: JBoss AS6: Mini (Stateful) EJB 3 Example using JBoss and Eclipse
                    phiboss

                    ... anyone deployed an EJB 3.0 Stateful (or -less) Bean (without ANT, maven, Entity-Beans) usinig Eclipse?

                    (JBoss or Glasfish does not matter which one).

                    Looking for a "Micro" Example!

                     

                    Must: EJB 3.0, Eclipse, Stateful or Stateless Bean, Server on different machine than the client.

                     

                    Who knows a tutorial for that?

                    • 7. Re: JBoss AS6: Mini (Stateful) EJB 3 Example using JBoss and Eclipse
                      wolfgangknauf

                      Hi Phi,

                       

                      I use Eclipse to develop and deploy, so I might help ;-).

                       

                      Which Eclipse version do you use? I assume it is "Indigo" and the edition ".for JavaEE developers", which includes at least the "Web Tools Platform" plugin? Or do you use even "JBoss Tools"?

                       

                      Eclipse itself cannot do remote deployment, but I assume that JBoss Tools are able to do so.

                       

                      If you made deployment work, you can check the JNDI names by using JNDIView: http://geekzguru.wordpress.com/2008/01/22/howto-view-the-jndi-tree-in-jboss/

                       

                      Best regards

                       

                      Wolfgang

                      • 8. Re: JBoss AS6: Mini (Stateful) EJB 3 Example using JBoss and Eclipse
                        phiboss

                        I use Eclipse (Indigo) together with "GlassFish" as Application Server now.

                        This works out of the box!

                         

                        Thanks for all your help.