我的代码包含quartz schedular 的基本示例。在正常的java 应用程序中它正在运行,但是当我将它转换为一个包并将它部署在karaf 中时它不起作用。
@Component
@Service
public class testImpl implements testI {
@Override
public void test() {
System.out.println("testImpl started");
try {
JobDetail job = JobBuilder.newJob(TestJob.class)
.withIdentity("testJob")
.build();
System.out.println("job \n");
Trigger trigger = TriggerBuilder.newTrigger()
.withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds(5)
.repeatForever())
.build();
System.out.println("trigger \n ");
//THIS PARTICULAR LINE ONWARDS THE CODE IS NOT EXCUTING IM NOT GETTING SYSOUT AFTER THIS LINE.
SchedulerFactory schFactory = new StdSchedulerFactory();
System.out.println("scheduler \n");
Scheduler sch = schFactory.getScheduler();
sch.start();
sch.scheduleJob(job, trigger);
} catch (Exception e) {
e.printStackTrace();
}
}
计划抛出异常,如
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.quartz.impl.StdSchedulerFactory.<init>(StdSchedulerFactory.java:298)
at com.ericsson.testImpl.testImpl.test(testImpl.java:77)
at com.ericsson.testConsumer.testConsumer.bindTestI(testConsumer.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
但据我所知,Karaf 内置了对 slf4j 的支持。无需显式添加 slf4j 包。