---
title: "快速入门：用xml启动Quartz任务"
author: "shp808"
date: "2011-11-08T15:55:31Z"
tags: ["Servlet", "Web", "XML", "quartz", "quartzinitializer"]
categories: ["编程语言"]
slug: "xml-quartz"
draft: false
lastmod: "2011-11-08T15:55:31Z"
id: 1243436
url: "https://shp808.iteye.com/blog/1243436"
---

1.下载Quartz 将quartz放到 yourappl/WEB-INF/lib 里面。 2.配置web.xml,启动Quartz服务. 在 yourappl/WEB-INF/web.xml 里添加以下内容。 QuartzInitializer Quartz Initializer Servlet org.quartz.ee.servlet.QuartzInitializerServlet 1 3.配置您的任务文件 quartz\_reminder.xml ,建立job 和 trigger. 在 yourappl/WEB-INF/web.xml 里新建文件 quartz\_reminder.xml 以下例子建立两个日程安排，一个是每隔15分钟执行scheduling.QuartzEmail任务， 一个是星期1-5 8：30AM执行scheduling.QuartzDailyReminder任务。您可以自建QuartzEmail.class,QuartzDailyReminder.class放置在 yourappl/WEB-INF/classes/scheduling 里进行测试。 注意一个日程是由一个job和一个trigger组成，代表任务定义和时间定义。 Job\_Email DEFAULT scheduling.QuartzEmail Trigger\_Email DEFAULT Job\_Email DEFAULT 0 0/15 * * * ? Job\_Daily\_Reminder DEFAULT scheduling.QuartzDailyReminder Trigger\_Daily\_Reminder DEFAULT Job\_Daily\_Reminder DEFAULT 0 30 8 ? * MON-FRI 4. 配置 quartz.properties ，建立Quartz实例 在 yourappl/WEB-INF/web.xml 里新建文件 quartz.properties # # Configure Main Scheduler Properties # org.quartz.scheduler.instanceName = TestScheduler org.quartz.scheduler.instanceId = one # # Configure ThreadPool # org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.threadCount = 5 org.quartz.threadPool.threadPriority = 4 # # Configure JobStore # org.quartz.jobStore.misfireThreshold = 5000 org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore # =========================================================================== # Configure SchedulerPlugins =============================================== # =========================================================================== org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingTriggerHistoryPlugin org.quartz.plugin.triggHistory.triggerFiredMessage = Trigger {1}.{0} fired job {6}.{5} at: {4, date, HH:mm:ss MM/dd/yyyy} org.quartz.plugin.triggHistory.triggerCompleteMessage = Trigger {1}.{0} completed firing job {6}.{5} at {4, date, HH:mm:ss MM/dd/yyyy} with resulting trigger instruction code: {9} org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin org.quartz.plugin.jobInitializer.fileName = /quartz\_reminder.xml org.quartz.plugin.jobInitializer.overWriteExistingJobs = false org.quartz.plugin.jobInitializer.failOnFileNotFound = true org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin org.quartz.plugin.shutdownhook.cleanShutdown = true 好了，现在重起jsp服务器，留意logs里面的输出，就可以测试您的日程有无生效了。