views:

791

answers:

4

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

+2  A: 

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

Alberto Zaccagni
+1  A: 

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

R. Kettelerij
+3  A: 

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'.

NawaMan
+1  A: 

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.

fvu