This is my first time working with Quartz. I am trying out a sample program that prints “Hello World” preodically. But when i try to run it i get an error saying
Exception in thread “main” java.lang.RuntimeException: Uncompilable
source code – org.quartz.JobDetail is abstract; cannot be instantiated
at QuartzAppSimpleTrigger.main(QuartzAppSimpleTrigger.java:18)
When i try it out in Netbeans it asks me to implement all abstract methods of JobDetail.
The following is my code sample.
import java.util.Date;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;
public class HelloSchedule {
public HelloSchedule() throws Exception {
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
sched.start();
JobDetail jd = new JobDetail("myjob", sched.DEFAULT_GROUP, HelloJob.class);
SimpleTrigger st = new SimpleTrigger("mytrigger", sched.DEFAULT_GROUP, new Date(),
null, SimpleTrigger.REPEAT_INDEFINITELY, 60L * 1000L);
sched.scheduleJob(jd, st);
}
public static void main(String args[]) {
try {
new HelloSchedule();
} catch (Exception e) {
}
}
}
And the HelloJob.java is
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import java.util.Date;
public class HelloJob implements Job {
public void execute(JobExecutionContext arg0) throws JobExecutionException{
System.out.println("Hello World Quartz Scheduler: " + new Date());
}
}
You are using the wrong version of Quartz.
JobDetailclass in Quartz 1.x was refactored toJobDetailinterface withorg.quartz.impl.JobDetailImplimplementation in Quartz 2.x.You should either replace Quartz 2.x with Quartz 1.x on your CLASSPATH or better use new 2.x API.