我正在尝试创建一个任务调度程序。我用石英。我跟着this示例。 我在maven中进行了依赖(测试2.2.1和2.2.2),我的HelloJob类实现了Job。
我有
public class HelloJob implements Job{
public void execute(JobExecutionContext context) throws JobExecutionException {
// Say Hello to the World and display the date/time
System.out.println("Hello World! - " + new Date());
JobDetail job = newJob(HelloJob.class)
.withIdentity("job1", "group1")
.build();
}
}
但我有消息:
The method newJob(Class<HelloJob>) is undefined for the type HelloJob
我尝试将JobDetail声明放在SimpleExample类中,但出现了同样的错误......
答案 0 :(得分:2)
方法newJob
在org.quartz.JobBuilder
中定义为静态。在您的班级中添加静态导入:
import static org.quartz.JobBuilder.*;