运行 Quartz Scheduler 程序时出现异常

发布于 2024-08-26 20:24:02 字数 1689 浏览 8 评论 0原文

我在运行我的 Quartz Schdular 程序时遇到异常。

异常跟踪

Mar 26, 2010 2:54:24 PM org.quartz.core.QuartzScheduler start
INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.
Exception in thread "main" java.lang.IllegalArgumentException: Job class must implement the Job interface.
    at org.quartz.JobDetail.setJobClass(JobDetail.java:291)
    at org.quartz.JobDetail.<init>(JobDetail.java:138)
    at com.Quarrtz.RanchSchedule.main(RanchSchedule.java:18)

下面是我包含的 Quartz-1.7.2.jar 和 我的类路径中的 Quartz-all-1.7.2.jar 以及 commom-logging 1.1.jar 和 jdk 6

这是我从 [JavaRanch 复制并粘贴的示例][1]

上页中的第一个示例

public interface Job {

    void execute (JobExecutionContext ctx);
}

public class RanchJob implements Job {

    public void execute (JobExecutionContext ctx) throws JobExecutionException {
        System.out.println("[JOB] Welcome at JavaRanch");
    }
}

public class RanchSchedule {

    public static void main (String[] args) {       
        try {
            SchedulerFactory factory = new org.quartz.impl.StdSchedulerFactory();

            Scheduler scheduler = factory.getScheduler();
            scheduler.start();

            JobDetail jobDetail = new JobDetail("ranchJob", null, RanchJob.class);
            // Fires every 10 seconds
            Trigger ranchTrigger = TriggerUtils.makeSecondlyTrigger(10); 
            ranchTrigger.setName("ranchTrigger");

            scheduler.scheduleJob(jobDetail, ranchTrigger);
        } catch (SchedulerException ex) {
            ex.printStackTrace();
        }
    }
}

I am getting he following Exception while running my Quartz Schdular program.

Below is the exception Trace

Mar 26, 2010 2:54:24 PM org.quartz.core.QuartzScheduler start
INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.
Exception in thread "main" java.lang.IllegalArgumentException: Job class must implement the Job interface.
    at org.quartz.JobDetail.setJobClass(JobDetail.java:291)
    at org.quartz.JobDetail.<init>(JobDetail.java:138)
    at com.Quarrtz.RanchSchedule.main(RanchSchedule.java:18)

I have included Quartz-1.7.2.jar and
Quartz-all-1.7.2.jar in my class path along with commom-logging 1.1.jar and jdk 6

this is an example i have copy and pasted from [JavaRanch][1]

First example in the above page

public interface Job {

    void execute (JobExecutionContext ctx);
}

public class RanchJob implements Job {

    public void execute (JobExecutionContext ctx) throws JobExecutionException {
        System.out.println("[JOB] Welcome at JavaRanch");
    }
}

public class RanchSchedule {

    public static void main (String[] args) {       
        try {
            SchedulerFactory factory = new org.quartz.impl.StdSchedulerFactory();

            Scheduler scheduler = factory.getScheduler();
            scheduler.start();

            JobDetail jobDetail = new JobDetail("ranchJob", null, RanchJob.class);
            // Fires every 10 seconds
            Trigger ranchTrigger = TriggerUtils.makeSecondlyTrigger(10); 
            ranchTrigger.setName("ranchTrigger");

            scheduler.scheduleJob(jobDetail, ranchTrigger);
        } catch (SchedulerException ex) {
            ex.printStackTrace();
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿哥们儿 2024-09-02 20:24:02

您在源代码中编写了 Job 接口吗?

public interface Job {
    void execute (JobExecutionContext ctx);
}

如果是这样,您不必这样做。 Quartz 有自己的 Job 接口(在quartz.jar 中)。
只保留 RanchJob 和 RanchSchedule 类,它应该可以工作。

Have you written the Job interface in your source code ?

public interface Job {
    void execute (JobExecutionContext ctx);
}

If so, you don't have to do this. Quartz has its own Job interface (in the quartz.jar).
Keep only your RanchJob and RanchSchedule classes and it should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文