dimanche 1 octobre 2017

How to get class reference by String name?

The am attempting to make the following method call dynamic:

JobDetail job = newJob(RunMeJob.class)
                  .withIdentity("myJob", "group1")
                  .build();

By doing the following:

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();
}

But I am receiving the following error:

The method newJob(Class< ? extends Job>) in the type JobBuilder is not applicable for the arguments (Class< capture#3-of ?>)

How can I dynamically specify the class?





Aucun commentaire:

Enregistrer un commentaire