Run a Quartz job with a Java class name stored in the database

I have two works in Quartz that will work well, but I believe that I need to use code, for example:

jd = new JobDetail(sj.getJobName(), scheduler.DEFAULT_GROUP, PollJob.class);
ct = new CronTrigger(sj.getJobTrigger(), scheduler.DEFAULT_GROUP, "0 20 * * * ?");
        scheduler.scheduleJob(jd, ct);

I need to copy the PollJob.class file to run the job, and sj is the object that is read from the database containing the PollJob information. But I would also like to install PollJob.class from the database. I tried casting in class:

Class cls = Class.forName(sj.getJobJavaClassFile());
jd = new JobDetail(sj.getJobName(), scheduler.DEFAULT_GROUP, cls));

And using the class reference directly as:

    jd = new JobDetail(sj.getJobName(), scheduler.DEFAULT_GROUP, Class.forName sj.getJobJavaClassFile()));

But the work is simply not being done. There are no exceptions that I see and do not trace the trace?

I am running the JVM on Windows 7.

Any ideas?

Mr. Morgan.

0
source share
1 answer

, String, ? .

, , BatchJobDto. , , String .. , batchJobDto.getClassName() , ( "com.foo.bar.MyJob" - ). , String . :

Class<? extends Job> jobClass = null;
try {
    jobClass = (Class<? extends Job>)
                  Class.forName(batchJobDto.getClassName());
} catch(ClassNotFoundException e) {
    logger.error("createJob(): ClassNotFoundException on job class {} - {}",
        batchJobDto.getClassName(), e.getMessage());
} catch(Exception e) {
    logger.error("createJob(): Exception on job class {} - {}",
        batchJobDto.getClassName(), e.getMessage());
}

slf4j, ( "{}", ).

, classname , Quartz ( Job), , .

0

All Articles