gpt4 book ai didi

java - 尝试在 quartz 作业中使用外部库时出现 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-29 05:34:37 24 4
gpt4 key购买 nike

所以我有一个完美工作的 quartz 工作,定义如下:

package willkara.monkai.jobber;

import java.util.Date;
import org.joda.time.DateTime;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import willkara.monkai.impl.MonKaiClientImpl;


/* this is a test Quartz job to show that we can inject jobs into the jobscheduler from an external location */
public class tester implements Job {

public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
System.out.println("I REALLY HOPE THIS WORKS");
DateTime dt = new DateTime();

System.out.println(dt.getDayOfYear());

}
}

每当我在网站上的 quartz 调度程序中运行该作业时,一切都运行良好,直到它尝试运行 JodaTime 命令。

它输出了 I REALLY HOPE THIS WORKS 文本,但在那之后我得到了这个堆栈跟踪:

I REALLY HOPE THIS WORKS
2013-11-13 14:31:16,180 ERROR QuartzScheduler_Worker-1 org.quartz.core.JobRunShell - Job DEFAULT.qqq threw an unhandled Exception:
java.lang.NoClassDefFoundError: org/joda/time/DateTime
at willkara.monkai.jobber.tester.execute(tester.java:16)
at org.sakaiproject.component.app.scheduler.jobs.SpringJobBeanWrapper.execute(SpringJobBeanWrapper.java:70)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:534)
Caused by: java.lang.ClassNotFoundException: org.joda.time.DateTime
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 4 more
2013-11-13 14:31:16,183 ERROR QuartzScheduler_Worker-1 org.quartz.core.ErrorLogger - Job (DEFAULT.qqq threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NoClassDefFoundError: org/joda/time/DateTime]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:534)
Caused by: java.lang.NoClassDefFoundError: org/joda/time/DateTime
at willkara.monkai.jobber.tester.execute(tester.java:16)
at org.sakaiproject.component.app.scheduler.jobs.SpringJobBeanWrapper.execute(SpringJobBeanWrapper.java:70)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 1 more
Caused by: java.lang.ClassNotFoundException: org.joda.time.DateTime
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 4 more

我正在尝试运行我自己编写的不同外部库中的代码。整个项目使用maven管理。我只是将 JodaTime 用作测试以确保/查看它是否会运行来自外部库的代码。

最佳答案

问题是您已经在类路径中使用 JodaTime 库编译源代码,但它们在目标类路径中不可用。确保它们在您的应用服务器的 lib 目录中或将它们包含在您的工件中。

关于java - 尝试在 quartz 作业中使用外部库时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19963233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com