5 Replies Latest reply on May 3, 2013 8:52 AM by Irfan Basha

    Quartz integration with JBoss 7

    Irfan Basha Newbie

      Hi,

       

      I am trying to migrate our application from jboss 5.1 to jboss 7.1. We use Quartz schedular in jboss 5.1, but unfortunately jboss 7.1 doesn't support quartz.

       

      I read several discussions in this community forum, but was still not able to integrate quartz with jboss as 7.1.

       

      Would be glad if someone can let me know how to proceed.

       

      I have done the following, please correct me if I am wrong:

       

      1. Created a module for quartz:

           a. Created a folder structure JBoss 7\modules\org\quartz\main

            b. Added module.xml and quartz-all-2.0.2.jar

           c. Content of module.xml is:          

      <module xmlns="urn:jboss:module:1.1" name="org.quartz">
        <resources>
          <resource-root path="quartz-all-2.0.2.jar"/>
              <!-- Insert resources here -->
        </resources>
        <dependencies>
                <module name="org.slf4j"/>
                            <module name="javax.api"/>
        </dependencies>
      </module>
      

       

      2. Created a sample application with one QuartzJob:     

      package com.sample; 
      
      import javax.ejb.MessageDriven; 
      import org.jboss.ejb3.annotation.ResourceAdapter;
      import org.quartz.Job;
      import org.quartz.JobExecutionContext;
      import org.quartz.JobExecutionException; 
      import javax.ejb.ActivationConfigProperty; 
      
      @MessageDriven(activationConfig =
      {@ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0 0/1 * * * ?")})
      @ResourceAdapter("quartz-all-2.0.2.jar")
      
      
      public class QuartzMDB implements Job
      { 
        public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
        {
            System.out.println("Quartz job executed!");
        } 
      }
      

       

      3. Deployed the above program as jar in Standalone\deployment

       

      4. When I start the jboss server I get the following error: (I start the server with server-config=standalone-full.xml)

       

      java.lang.ClassNotFoundException: org.quartz.Job from [Module "deployment.QuartzMDB.jar:main" from Service Module Loader]

       

      full stack trace :

      14:31:58,716 WARN  [org.jboss.modules] (MSC service thread 1-5) Failed to define class com.sample.QuartzMDB in Module "deployment.QuartzMDB.jar:main" from Service Module Loader: java.lang.LinkageError: Failed to link com/sample/QuartzMDB (Module "deployment.QuartzMDB.jar:main" from Service Module Loader)
                at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396)
                at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243)
                at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73)
                at org.jboss.modules.Module.loadModuleClass(Module.java:517)
                at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
                at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
                at java.lang.Class.forName0(Native Method) [rt.jar:]
                at java.lang.Class.forName(Unknown Source) [rt.jar:]
                at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54)
                at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:63) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
                at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:55) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113)
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:]
                at java.lang.Thread.run(Unknown Source) [rt.jar:]
      Caused by: java.lang.NoClassDefFoundError: org/quartz/Job
                at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:]
                at java.lang.ClassLoader.defineClass(ClassLoader.java:820) [rt.jar:]
                at java.security.SecureClassLoader.defineClass(Unknown Source) [rt.jar:]
                at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327)
                at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391)
                ... 19 more
      Caused by: java.lang.ClassNotFoundException: org.quartz.Job from [Module "deployment.QuartzMDB.jar:main" from Service Module Loader]
                at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
                at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
                ... 24 more
      
      
      14:31:58,753 WARN  [org.jboss.modules] (MSC service thread 1-5) Failed to define class com.sample.QuartzMDB in Module "deployment.QuartzMDB.jar:main" from Service Module Loader: java.lang.LinkageError: Failed to link com/sample/QuartzMDB (Module "deployment.QuartzMDB.jar:main" from Service Module Loader)
                at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396)
                at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243)
                at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73)
                at org.jboss.modules.Module.loadModuleClass(Module.java:517)
                at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
                at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
                at java.lang.Class.forName0(Native Method) [rt.jar:]
                at java.lang.Class.forName(Unknown Source) [rt.jar:]
                at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54)
                at org.jboss.as.ejb3.deployment.processors.dd.DeploymentDescriptorMethodProcessor.handleStatelessSessionBean(DeploymentDescriptorMethodProcessor.java:97) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
                at org.jboss.as.ejb3.deployment.processors.dd.DeploymentDescriptorMethodProcessor.deploy(DeploymentDescriptorMethodProcessor.java:76) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113)
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:]
                at java.lang.Thread.run(Unknown Source) [rt.jar:]
      Caused by: java.lang.NoClassDefFoundError: org/quartz/Job
                at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:]
                at java.lang.ClassLoader.defineClass(ClassLoader.java:820) [rt.jar:]
                at java.security.SecureClassLoader.defineClass(Unknown Source) [rt.jar:]
                at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327)
                at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391)
                ... 19 more
      Caused by: java.lang.ClassNotFoundException: org.quartz.Job from [Module "deployment.QuartzMDB.jar:main" from Service Module Loader]
                at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
                at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
                ... 24 more
      
      
      14:31:58,800 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.deployment.unit."QuartzMDB.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."QuartzMDB.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "QuartzMDB.jar"
                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:]
                at java.lang.Thread.run(Unknown Source) [rt.jar:]
      Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014400: Could not load component class
                at org.jboss.as.ejb3.deployment.processors.dd.DeploymentDescriptorMethodProcessor.deploy(DeploymentDescriptorMethodProcessor.java:79)
                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
                ... 5 more
      Caused by: java.lang.ClassNotFoundException: com.sample.QuartzMDB from [Module "deployment.QuartzMDB.jar:main" from Service Module Loader]
                at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
                at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
                at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
                at java.lang.Class.forName0(Native Method) [rt.jar:]
                at java.lang.Class.forName(Unknown Source) [rt.jar:]
                at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
                at org.jboss.as.ejb3.deployment.processors.dd.DeploymentDescriptorMethodProcessor.handleStatelessSessionBean(DeploymentDescriptorMethodProcessor.java:97)
                at org.jboss.as.ejb3.deployment.processors.dd.DeploymentDescriptorMethodProcessor.deploy(DeploymentDescriptorMethodProcessor.java:76)
                ... 6 more
      
      
      14:31:58,829 INFO  [org.jboss.as] (MSC service thread 1-5) JBAS015951: Admin console listening on http://127.0.0.1:9990
      14:31:58,829 ERROR [org.jboss.as] (MSC service thread 1-5) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 3151ms - Started 176 of 258 services (1 services failed or missing dependencies, 80 services are passive or on-demand)
      14:31:58,830 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "QuartzMDB.jar" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"QuartzMDB.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"QuartzMDB.jar\".POST_MODULE: Failed to process phase POST_MODULE of deployment \"QuartzMDB.jar\""}}
      14:31:58,839 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015877: Stopped deployment QuartzMDB.jar in 7ms
      14:31:58,841 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
      JBAS014777:   Services which failed to start:      service jboss.deployment.unit."QuartzMDB.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."QuartzMDB.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "QuartzMDB.jar"
      
      
      14:31:58,850 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"QuartzMDB.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"QuartzMDB.jar\".POST_MODULE: Failed to process phase POST_MODULE of deployment \"QuartzMDB.jar\""}}}}
      
      

       

       

      Any suggestions would be great.

       

      Thanks,

      Irfan

        • 1. Re: Quartz integration with JBoss 7
          Stephen Coy Master

          You will find the solution to your ClassnotFoundExceptions in Class Loading in AS7.

           

          I suspect that you will encounter other issues however.

          • 2. Re: Quartz integration with JBoss 7
            Irfan Basha Newbie

            Hi Stephen,

             

            Thanks for the reply.

             

            What other issues do you think i'll encounter ?

            Is there any alternative for using Quartz ? (Can I use Timemachine or TimeService)

             

            Thanks,

            Irfan

            • 3. Re: Quartz integration with JBoss 7
              Stephen Coy Master

              The obvious alternative is JEE6 EJB timers. These will work even if implemented in a web application.

               

              You may find that you need to deploy the quartz jar with your application (rather than in a JBoss module) in order for the @ResourceAdapter annotation to function correctly.

              • 4. Re: Quartz integration with JBoss 7
                Irfan Basha Newbie

                Hi Stephen,

                 

                Thanks again for the reply.

                 

                I am trying to deploy the quartz jar with my sample application. But I am not sure how to do it.

                Could you kindly tell me how can I do that.

                 

                Thanks in advance,

                Irfan

                • 5. Re: Quartz integration with JBoss 7
                  Irfan Basha Newbie

                  Hi,

                   

                  I got it working. I did the following:

                   

                  1. Created a module for quartz:

                       a. Created a folder structure JBoss 7\modules\org\quartz\main

                        b. Added module.xml and quartz-all-2.0.2.jar

                       c. Content of module.xml is same as above.

                   

                  2. Created a class "SchedulerBean" as below:

                  @Startup

                  @Singleton

                  public class SchedulerBean {

                   

                   

                    @PostConstruct

                    void init() {

                     

                      try {

                        Scheduler sched = new StdSchedulerFactory().getScheduler();

                     

                  JobDetail testjob = JobBuilder.newJob(TestJob.class)

                    .withIdentity("testjob", "testgroup")

                    .build();

                       

                  SimpleTrigger trigger = TriggerBuilder.newTrigger()

                    .withIdentity("testtrigger", "testgroup")

                    .withSchedule(SimpleScheduleBuilder.simpleSchedule()

                       .withIntervalInSeconds(10)

                       .repeatForever())

                    .build();

                       

                  sched.scheduleJob(testjob, trigger);

                        sched.start();

                      }

                      catch (Throwable t) {

                        // log exception

                      }

                    }

                  }

                   

                  3.  The Test Job  implements Quartz Job:

                  public class TestJob implements Job {

                   

                   

                    @Override

                    public void execute(JobExecutionContext context) throws JobExecutionException {

                      System.out.println("Quartz test job executed!");

                    }

                  }

                   

                  4. Finally run the standalone.bat with standalone-full.xml as server config.

                   

                  (I followed this link: http://entjavastuff.blogspot.de/2012/01/jboss-7-missing-scheduling-and-jmx.html)

                   

                  Now as soon as I deploy the jar in jboss as7, the job also starts. I still have to test if other functions of Quartz are working as it should.