All the examples in this chapter have shown how to set up listeners using a programmatic approach. This chapter wouldn't be complete if we didn't provide at least an example of configuring a listener using a declarative approach with the quartz_jobs.xml file.
Starting with Quartz 1.5, you are able to specify listeners in the job-definition file, otherwise known as the quartz_jobs.xml file. Listing 7.14 shows an example of using a global listener.
Listing 7.14. Quartz Listeners Can Be Implemented with the quartz_jobs.xml File
PrintInfoJob DEFAULT SimpleJobListener org.cavaness.quartzbook.common.PrintInfoJob printJobTrigger DEFAULT PrintInfoJob DEFAULT 2005-09-13 6:10:00 PM -1 10000 |
You see in Listing 7.14 the additional <job-listener> element with the two required attributes:
The class-name property identifies the fully qualified name of the listener class. The name attribute assigns a logical name to the listener used in the <job-detail> element.
The next step is to define a <job-listener-ref> element in the <job-detail> element in the same file for each job that you want the listener on. The value of the element must match the name property of one of the defined <job-listener> elements in the file.
After you have done that, make sure you've configured the Scheduler to use the JobInitializationPlugin by setting the properties in the quartz.properties file. Quartz plug-ins are discussed in detail in the next chapter. For now, just add the following lines to your quartz.properties file:
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin org.quartz.plugin.jobInitializer.overWriteExistingJobs = true org.quartz.plugin.jobInitializer.failOnFileNotFound = true org.quartz.plugin.jobInitializer.validating=false
Then name your XML file quartz_jobs.xml and put the file in your classpath.
Thread Use in Listeners |
Scheduling in the Enterprise
Getting Started with Quartz
Hello, Quartz
Scheduling Jobs
Cron Triggers and More
JobStores and Persistence
Implementing Quartz Listeners
Using Quartz Plug-Ins
Using Quartz Remotely
Using Quartz with J2EE
Clustering Quartz
Quartz Cookbook
Quartz and Web Applications
Using Quartz with Workflow
Appendix A. Quartz Configuration Reference