aditya1508 aditya1508 - 2 years ago 193
Java Question

java.lang.NoClassDefFoundError in ubuntu terminal

I am crating a cron scheduler for which i am using the following code:-

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 {
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();



and I am compiling teh following code in terminal with the following statement:-

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: "

and on running the code I am using the following statement:-

java CronSched

and I am getting the following error:-

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(
at java.lang.Class.privateGetMethodRecursive(
at java.lang.Class.getMethod0(
at java.lang.Class.getMethod(
at sun.launcher.LauncherHelper.validateMainClass(
at sun.launcher.LauncherHelper.checkAndLoadMain(

Caused by: java.lang.ClassNotFoundException: org.quartz.ScheduleBuilder
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
... 7 more

What to Do?

Answer Source

You have to add all necessaries jars to your runtime classpath.

java -cp "quartz-2.2.3.jar:...." CronSched 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download