Reputation: 147
i'm trying to use quartz to schedule jobs in grails with out using the plugin. this is the code:
1 - RunMeTask.java
package tt;
public class RunMeTask {
public void printMe() {
System.out.println("Run Me ~");
}
}
2 - resources.groovy (under conf/spring)
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SimpleTriggerBean;
import tt.RunMeTask
beans = {
runMeTask(RunMeTask){}
runMeJob(JobDetailFactoryBean) {
targetObject = ref('runMeTask')
targetMethod = "printMe"
}
simpleTrigger(SimpleTriggerBean){
jobDetail = ref('runMeJob')
repeatInterval = "5000"
startpDelay = "1000"
}
schedulerFactoryBean(SchedulerFactoryBean){
jobDetails = [ref('runMeJob')]
triggers = [ref('simpleTrigger')]
}
}
i get the following exception: Error Fatal error during compilation org.apache.tools.ant.BuildException: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.SimpleTriggerBean has interface org.quartz.SimpleTrigger as super class (Use --stacktrace to see the full trace)
can anyone help?
Upvotes: 1
Views: 591
Reputation: 147
ok i figure it out. wasn't that hard when i think about it.the good thing about it its just as simple as you would do it in java and no plugin that may or may not work on grails certain version or any trouble that can caused by using a plugin.
there is 1 change in the code from the question:
RunMeTask.java (this can also be RunMeTask.groovy) must implement runnable and so it look like this:
package tt;
import java.io.File;
import java.io.IOException;
import java.util.Random;
public class RunMeTask implements Runnable {
static Random r = new Random();
public void printMe() throws IOException {
File f = new File("c:\ofer.txt"+r.nextInt());
f.createNewFile();
System.out.println("fff");
}
public void run(){
try {
printMe();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
one funny thing is the println of "fff" occures only 2 times but a new file is created as expected every 5 seconds.
ok so thats it now a new file is created every 5 seconds in your c directory. no plugin and no hassle. if anyone know why the System.out.println("fff"); occures only 2 times i will be happy to know.
thanks
Upvotes: 1