Using Quartz 1.8.5 with tomcat without Spring

 

在网上找了些文章来看,都是比较早的东东,有些地方的配置已经改变了,总结了一下,记录在这里。

1、从http://quartz-scheduler.org下载quartz-1.8.5.tar.gz,解压缩到目录quartz-1.8.5中


2、添加quartz-1.8.5.jar及quartz-1.8.5\lib目录中的jar文件到项目的lib目录中

3、在项目中添加对quartz-1.8.5.jar的引用

4、编写MyJob 

import  java.util.Date;

import  org.apache.commons.logging.Log;
import  org.apache.commons.logging.LogFactory;
import  org.quartz.Job;
import  org.quartz.JobExecutionContext;
import  org.quartz.JobExecutionException;

public   class  MyJob  implements  Job{

       private   static  Log  log  = LogFactory.getLog(StatServer. class );
      
       @Override
       public   void  execute(JobExecutionContext arg0)  throws  JobExecutionException {
            System. out .println( "Hello, "  +  new  Date());
      }

}

5、添加quartz.properties文件到classes目录中(注意红色的部分)

org.quartz.scheduler.instanceName = TestScheduler
 org.quartz.scheduler.instanceId =  one
 
org.quartz.threadPool.class =  org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount =   2
org.quartz.threadPool.threadPriority =  4
 
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.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames =  quartz_job.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound =  true
org.quartz.plugin.shutdownhook.class =  org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown =  true

6、添加quartz_job.xml到classes目录中

<?xml version="1.0" encoding="UTF-8"?>
< job-scheduling-data
       xmlns = "http://www.quartz-scheduler.org/xml/JobSchedulingData"
       xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation = "http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
       version = "1.8" >
       < schedule >
             < job >
                   < name >MyJob1 </ name >
                   < group >jobGroup1 </ group >
                   < job-class > MyJob </ job-class >
             </ job >
             < trigger >
                   < cron >
                         < name > Trigger1 </ name >
                         < group >triggerGroup1 </ group >
                         < job-name >MyJob1 </ job-name >
                         < job-group >jobGroup1 </ job-group >
                         < cron-expression > 0/5 * * * * ? </ cron-expression >
                   </ cron >
             </ trigger >
       </ schedule >
</ job-scheduling-data >

7、在web.xml中添加listener

     <context-param>
         <param-name>quartz:config-file</param-name>
          < param-value > /quartz.properties </ param-value >
      </ context-param >
      < context-param >
          < param-name > quartz:shutdown-on-unload </ param-name >
          < param-value > true </ param-value >
      </ context-param >
      < context-param >
          < param-name > quartz:start-on-load </ param-name >
          < param-value > true </ param-value >
      </ context-param >
    
      < listener >
          < listener-class >
             org.quartz.ee.servlet.QuartzInitializerListener
          </ listener-class >
      </ listener >

8、启动Tomcat,查看控制台输出。

你可能感兴趣的:(spring,tomcat,Date,quartz,jar,encoding)