I am attempting to make the following method call dynamic:
JobDetail job = newJob(RunMeJob.class)
.withIdentity("myJob", "group1")
.build();
private void scheduleJob(final SchedulerJob job, final SchedulerTrigger trigger) {
final String fullyQualifiedName = "com.crm.scheduler.job.RunMeJob";//"com.crm.scheduler.job" + job.getImplementation();
Class<?> cls = Class.forName(fullyQualifiedName, false, null);
JobDetail jobDetail = newJob(cls)
.withIdentity(job.getExternalReference(), trigger.getExternalReference())
.build();
}
The method newJob(Class< ? extends Job>) in the type JobBuilder is not
applicable for the arguments (Class< capture#3-of ?>)
RunMeJob
package com.crm.scheduler.job;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;
import com.crm.scheduler.task.RunMeTask;
@Component
public class RunMeJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
new RunMeTask().printMe();
}
}
You have the right idea, basically, but you can't pass any old Class
object to the newJob
method - it must be a Class
instance that represent a Job
, and has to be specified as such in its generics:
Class<? extends Job> cls =
(Class<Job>) Class.forName(fullyQualifiedName, false, null);