How to enable Quartz scheduling in Jboss AS 7.0?

14,000

The NoClassDefFoundError could be related to a missing dependency. Is the quartz jar-file available in your jboss? Maybe this documentation helps: https://docs.jboss.org/author/display/AS7/How+do+I+migrate+my+application+from+AS5+or+AS6+to+AS7#HowdoImigratemyapplicationfromAS5orAS6toAS7-HowtoResolveClassNotFoundExceptionsandNoCLassDefFoundErrors

Here's my workaround for using quartz in JBoss 7:

Unfortunately AS7 Final doesn't support the @Schedule annotation (see JBoss issue AS7-1158)

So I packed the quartz jar via maven dependencies with my EAR file.

Then I use this startup bean to add the jobs and start the scheduler as described in the quartz examples: http://quartz-scheduler.org/docs/examples/index.html

@Singleton
@Startup
public class StartupBean
{

    @PostConstruct
    private void scheduleJobs()
    {
         // Exception Handling omitted
         final Scheduler sched = new StdSchedulerFactory().getScheduler();
         sched.scheduleJob( createJob(), createTrigger());
         sched.start();
    }

}
Share:
14,000
willtardy
Author by

willtardy

Updated on June 27, 2022

Comments

  • willtardy
    willtardy almost 2 years

    Quartz doesn't appear to be included with the default install of Jboss AS 7.0 Final (full). Deployment of my EAR appears to fail when the Message Driven Bean (MDB) "FareMonitorBean" is attempted to be loaded. This MDB is what the quartz schedule executes.

    Error message:

    10:00:34,034 WARN  [org.jboss.modules] (MSC service thread 1-7) Failed to define class com.myproject.beans.FareMonitorBean in Module "deployment.myprojectEAP.ear.myprojectEJB.jar:main" from Service Module Loader: java.lang.LinkageError: Failed to link com/myproject/beans/FareMonitorBean (Module "deployment.myprojectEAP.ear.myprojectEJB.jar:main" from Service Module Loader)
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:401)
    .....
    Caused by: java.lang.NoClassDefFoundError: org/quartz/Job
    at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_26]
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) [:1.6.0_26]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615) [:1.6.0_26]
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) [:1.6.0_26]
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:397)
    ... 18 more
    

    Summary of MDB "FareMonitorBean" class file :

    @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = EJBConstants.FARE_MONITOR_QUARTZ_SCHEDULE_STRING) })
    @ResourceAdapter("quartz-jboss-2.0.2.jar")
    public class FareMonitorBean implements Job {
    
        public void execute(JobExecutionContext arg0) throws JobExecutionException {
            ....
        }
    }
    

    Based on the JBoss documentation, my guess is that an "Extension" and "Subsystem" needs to be configured for Quartz in standalone/configuration/standalone.xml, however I'm not sure how to do this. I have searched google, jboss forums, quartz support doco and can't find anything. It seems a bit poor to me that Quartz doesn't work with a "final" release of Jboss, as surely a scheduler is a common and required feature of a fully-fledged application server?!

    Any suggestions or examples I could follow to get it working?


    UPDATE August 28th 2011:

    Could someone please help me with this issue? I'm having stability issues and numerous bugs with JBoss 6.0, and contemplating switching to GlassFish 3.1 if Jboss continues to be a challenging endevour. Is it just me or is Jboss just full of bugs and issues?!

  • willtardy
    willtardy over 12 years
    Thank you for your answer. I will try to implement your solution. Question though: Jboss 7.0 Final doesn't come with any quartz files, so where did you get the quartz jar file from that you've got working with Jboss 7?
  • Thomas Traude
    Thomas Traude over 12 years
    I use Maven to package the EAR file: put the dependency of quartz into the pom.xml as described here: quartz-scheduler.org/download/download-catalog.html. Then the maven-ear-plugin generates the EAR file and packs the dependency within the lib directory inside the EAR.
  • javatestcase
    javatestcase over 11 years
    I'm using JBoss AS7.1 and was able to use @Schedule. I'm just using a simple EJB Timer Bean right now.