我正在使用以下代码创建cron调度程序:

import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.ScheduleBuilder;

public class CronSched {

public static void main(String[] args) throws SchedulerException {
    System.out.println("Started");
    JobDetail job = JobBuilder.newJob(CronJob.class).build();
    Trigger t1 = TriggerBuilder.newTrigger().withIdentity("MAILER").withSchedule(CronScheduleBuilder.cronSchedule("0 33 2 1/1 * ? *")).build();
    Scheduler sc = StdSchedulerFactory.getDefaultScheduler();

    sc.start();
    sc.scheduleJob(job,t1);
  }

}


我正在使用以下语句在终端中编译以下代码:

javac -cp ".:/home/aditya/CronSched/lib/quartz-2.2.3.jar: /home/aditya/CronSched/lib/slf4j-api-1.7.25.jar: /home/aditya/CronSched/lib/slf4j-simple-1.7.25.jar: " CronSched.java


在运行代码时,我使用以下语句:

java CronSched


我收到以下错误:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/quartz/ScheduleBuilder
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

Caused by: java.lang.ClassNotFoundException: org.quartz.ScheduleBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more


该怎么办?

最佳答案

您必须将所有必需的jar添加到运行时类路径。

java -cp "quartz-2.2.3.jar:...." CronSched

10-08 15:03