ubuntu终端中的java.lang.NoClassDefFoundError

时间:2017-08-16 13:09:04

标签: java ubuntu terminal cron

我正在创建一个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

怎么做?

1 个答案:

答案 0 :(得分:2)

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

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