I am new to Quartz and I'm running into a compiling error. I am simply trying to get the HelloJob to run based on Quartz's Lesson 1 for Hello World. I am having trouble declaring a JobDetail
with the error: The method newJob(Class<? extends Job>)
in the type JobBuilder
is not applicable for the arguments (Class)".
Originally, the code had 3 errors at newJob
, newTrigger
, and simpleSchedule
was
// define the job and tie it to our HelloJob class
JobDetail job = newJob(HelloJob.class)
.withIdentity("job1", "group1")
.build();
// Trigger the job to run now, and then repeat every 40 seconds
Trigger trigger = newTrigger()
.withIdentity("trigger1", "group1")
.startNow()
.withSchedule(simpleSchedule()
.withIntervalInSeconds(40)
.repeatForever())
.build();
without JobBuilder.newJob(...), TriggerBuilder.newTrigger(...), SimpleScheduleBuilder.simpleSchedule(...). Unlike the example given, I went ahead and added the imports and attached the class calls in front of newJob, newTrigger, etc. which got rid of 2/3 errors. But it seems the error persists with
JobDetail job = JobBuilder.newJob(HelloJob.class)
.withIdentity("job1", "group1")
.build();
I have also tried replacing my job declaration with
JobDetail job = new JobDetail("job1", "group1", HelloJob.class);
but that ends with Cannot instantiate the type JobDetail
and it seems like a few examples out there do this.
Will really appreciate clarification,
Thanks!
Holds state information for Job instances. JobDataMap instances are stored once when the Job is added to a scheduler. They are also re-persisted after every execution of StatefulJob instances. JobDataMap instances can also be stored with a Trigger .
new JobKey("jobName", "jobGroupName"); As long as your job name and job group name is the same with which you created your job, you will be able to get your job detail.
JobDetails are meta data related to a Job implementation, they hold a reference to the Job you want to run and allow you to provide some additional data to your Job. Conveys the detail properties of a given Job instance. JobDetails are to be created/defined with JobBuilder.
A context bundle containing handles to various environment information, that is given to a JobDetail instance as it is executed, and to a Trigger instance after the execution completes.
You need to have this line of code:
import static org.quartz.JobBuilder.*;
And then in should work. Hopefully.
Edit: AND MAKE SURE 'HELLOJOB' IMPLEMENTS JOB!!
There.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With