编写每小时执行一次的java代码(quartz)

发布于 2024-08-08 07:35:18 字数 1705 浏览 2 评论 0原文

有人可以纠正我吗,我在网上发现了这个示例,而其他一些示例则不起作用,这个特定的示例引发了以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/SetUtils
    at org.quartz.JobDetail.<init>(JobDetail.java:85)
    at tralala.org.xml.CronSchedule.<init>(CronSchedule.java:13)
    at tralala.org.xml.CronSchedule.main(CronSchedule.java:20)

这是代码:

CronJob.java

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class CronJob implements Job {
  public void execute(JobExecutionContext arg0) throws JobExecutionException {
    System.out.println("PRINT SOME TEXT LINE");
  }
}

CronSchedule.java

import org.quartz.CronTrigger;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.JobDetail;

public class CronSchedule {
  public CronSchedule ()throws Exception {
    SchedulerFactory sf=new StdSchedulerFactory();
    Scheduler sched=sf.getScheduler();
    JobDetail jd=new JobDetail("job1","group1",CronJob.class);
    CronTrigger ct=new CronTrigger("cronTrigger","group2","0 0/1 * * * ?");
    sched.scheduleJob(jd,ct);
    sched.start();
  }
  public static void main(String args[]){
    try{    
        new CronSchedule();
    }catch(Exception e){}
  }
}

我只想运行(实际上有效)任何石英的例子..我已经搜索了一段时间了,每个例子要么有编译错误,要么像这个(罕见的)抛出错误。我只是想运行这个或任何一个..只是为了通过一个具体的例子来了解一些内容。我一直在阅读 http://www.opensymphony.com/quartz/wikidocs/TutorialLesson1 .html,示例无法编译..有什么建议吗? tnx

Can someone please correct me, I've found this example online and bunch of others not working, this particular example throws the following error :

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/SetUtils
    at org.quartz.JobDetail.<init>(JobDetail.java:85)
    at tralala.org.xml.CronSchedule.<init>(CronSchedule.java:13)
    at tralala.org.xml.CronSchedule.main(CronSchedule.java:20)

Here is the code :

CronJob.java

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class CronJob implements Job {
  public void execute(JobExecutionContext arg0) throws JobExecutionException {
    System.out.println("PRINT SOME TEXT LINE");
  }
}

CronSchedule.java

import org.quartz.CronTrigger;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.JobDetail;

public class CronSchedule {
  public CronSchedule ()throws Exception {
    SchedulerFactory sf=new StdSchedulerFactory();
    Scheduler sched=sf.getScheduler();
    JobDetail jd=new JobDetail("job1","group1",CronJob.class);
    CronTrigger ct=new CronTrigger("cronTrigger","group2","0 0/1 * * * ?");
    sched.scheduleJob(jd,ct);
    sched.start();
  }
  public static void main(String args[]){
    try{    
        new CronSchedule();
    }catch(Exception e){}
  }
}

I just wanna run(that is actually works) any example of quartz .. I've been searching for some time now and every example either has compile error or like this one(rare one) throws an error. I just wanna run it this one or any .. just to get some inside with a concrete example. I've been reading http://www.opensymphony.com/quartz/wikidocs/TutorialLesson1.html, the examples don't compile .. any suggestions ? tnx

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

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

发布评论

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

评论(4

猫瑾少女 2024-08-15 07:35:18

该错误只是表明您的类路径中没有 org.apache.commons.collections.SetUtils 类。所以你应该确保这一点。您可以从此处下载该库。

然后解压下载文件。您应该看到一个文件 commons-collections-3.2.1.jar。您只需将该文件放在类路径中即可。或者使用选项“-cp commons-collections-3.2.1.jar”运行它。

The error just shows that you don't have the class org.apache.commons.collections.SetUtils in your class path. So you should ensure that. You can download the library from here.

Then extract the download file. You should see a file commons-collections-3.2.1.jar. You just place that file in your class path. OR run it with the option '-cp commons-collections-3.2.1.jar'.

黄昏下泛黄的笔记 2024-08-15 07:35:18

将包含 SetUtils 类的库添加到类路径。
您可以在此处找到它。

Add to the class path the library containing the SetUtils class.
You can find it here.

╰ゝ天使的微笑 2024-08-15 07:35:18

您应该将 commons-collections (v3.1) 添加到您的类路径中。它也捆绑在 Quartz 发行版中。

You should add commons-collections (v3.1) to you classpath. It's also bundled in the Quartz distribution.

深空失忆 2024-08-15 07:35:18

如果您从 Quartz 发行版存档中捆绑的示例开始,这对您来说可能会容易得多。它们位于 examples 子目录中,每个示例都有一个运行它的脚本(当然还有基于 ant 的编译脚本)。研究这些脚本以了解所有内容如何组合在一起。由于 Quartz 捆绑了所有需要的依赖项,您应该能够运行这些示例而无需下载任何内容。

It will probably be much easier for you if you start with the examples that come bundled with in the Quartz distribution archive. They are in the examples subdirectory and for each example there's a script to run it (alongside the ant-based compilation script of course). Study these scripts to see how everything fits together. As Quartz comes bundled with all needed dependencies you should be able to run the examples without downloading whatsoever.

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