Welcome to the QuickStart guide for Quartz 1.x. As this guide takes shape, expect to see details of:
NB. At the time of writing, the latest version of Quartz is 1.4.3. The guide will be version-independent wherever possible, but bear this fact in mind. Download & InstallationTo download Quartz, visit http://sourceforge.net/projects/quartz/ and click the download link next to the Quartz 1.4 package. If you can't be bothered with all of that, here are direct download links for the various pieces of Quartz:
Once you've downloaded and unpacked the zipfile, it's time to install it so that your application can see it. The JARsThe Quartz package includes a number of jar files, located in lib under the main Quartz directory. The main Quartz library is imaginatively named quartz.jar. In order to use any of Quartz's features, this jar must be located on your classpath. Once you've downloaded Quartz, unzip it somewhere, grab quartz.jar and put it where you want it. (If you need information on how to unzip files, go away and learn before you go anywhere near a development environment or the Internet in general. Seriously.) I use Quartz primarily within an application server environment, so my preference is to include quartz.jar within my enterprise application (.ear file). However, if you want to make Quartz available to many applications then simply make sure it's on the classpath of your appserver. Quartz depends on a number of jars. To use all the features of Quartz, all of these jars must also exist on your classpath. If you're building a standalone Quartz application, I suggest you simply add all of them to the classpath. If you're using Quartz within an app server environment, at least some of the jars will already exist on the classpath, so you can afford (if you want) to be a bit more selective as to which jars you include. NB. In an appserver environment, beware of strange results when accidentally including two different versions of the same jar. For example, WebLogic includes an implementation of J2EE (inside weblogic.jar) which may differ to the one in servlet.jar. In this case, it's usually better to leave servlet.jar out of your application, so you know which classes are being utilised. The properties fileQuartz uses a properties file called (again, kudos on the originality) quartz.properties. This isn't necessary at first, but to use anything but the most basic configuration it must be located on your classpath. Again, to give an example based on my personal situation, my application was developed using WebLogic Workshop. I keep all of my configuration files (including quartz.properties) in a project under the root of my application. When I package everything up into a .ear file, the config project gets packaged into a .jar which is included within the final .ear. This automatically puts quartz.properties on the classpath. Building from the source codeWatch this space for details on how to build Quartz yourself, for whatever reason you may have (I won't pry into your private reasons...). ConfigurationThis is the big bit! Quartz is a very configurable application. The best way to configure Quartz is to edit quartz.properties. The first thing to do is to look at example_quartz.properties, located in docs\config under the main Quartz directory. Alternatively, click the link below to view the version of example_quartz.properties that is distributed with Quartz 1.4.2: I would suggest you create your own quartz.properties based on the example file, rather than making a copy of example_quartz.properties and deleting the bits you don't need. It's neater that way, and you'll explore more of what Quartz has to offer. NB. I've discovered that example_quartz.properties doesn't contain all of the possible properties. Hopefully this will be remedied in the next version. To get up and running quickly, a basic quartz.properties looks something like this: org.quartz.scheduler.instanceName = Sched1 org.quartz.scheduler.instanceId = 1 org.quartz.scheduler.rmi.export = false org.quartz.scheduler.rmi.proxy = false org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.threadCount = 3 org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore The scheduler created by this configuration has the following characteristics:
Even if you have a database and want to use it with Quartz, I suggest you get Quartz working with the RamJobStore before you open up a whole new dimension by working with a database. Starting a sample applicationNow you've downloaded and installed Quartz, it's time to get a sample application up and running. The following code obtains an instance of the scheduler, starts it, then shuts it down: QuartzTest.java import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.impl.StdSchedulerFactory; public class QuartzTest { public static void main(String[] args) { try { // Grab the Scheduler instance from the Factory Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); // and start it off scheduler.start(); scheduler.shutdown(); } catch (SchedulerException se) { se.printStackTrace(); } } } NB. Once you obtain a scheduler using StdSchedulerFactory.getDefaultScheduler(), your application will not terminate until you call scheduler.shutdown(). If you have not set up logging, all logs will be sent to the console and your output will look something like this: 16-Dec-2004 16:15:21 org.quartz.simpl.SimpleThreadPool initialize INFO: Job execution threads will use class loader of thread: main 16-Dec-2004 16:15:22 org.quartz.simpl.RAMJobStore initialize INFO: RAMJobStore initialized. 16-Dec-2004 16:15:22 org.quartz.impl.StdSchedulerFactory instantiate INFO: Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties' 16-Dec-2004 16:15:22 org.quartz.impl.StdSchedulerFactory instantiate INFO: Quartz scheduler version: 1.4.2 16-Dec-2004 16:15:22 org.quartz.core.QuartzScheduler start INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started. 16-Dec-2004 16:15:22 org.quartz.core.QuartzScheduler shutdown INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutting down. 16-Dec-2004 16:15:22 org.quartz.core.QuartzScheduler pause INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED paused. 16-Dec-2004 16:15:22 org.quartz.core.QuartzScheduler shutdown INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutdown complete. |