| Author |
Message |
|
|
Well, as a solution, I've called quartz.properties through a servlet, and for jobs.xml, I've dynamically modified it path in the properties file.
InitConfServlet :
Code:
private void initQuartz() throws Exception{
/* to continue using the Quartz.properties file,
* I have to modify jobs.xml localization, which
* have to be set dynamically */
Properties quartzProperties = new Properties();
String quartzPropertiesFileName = configsFolder+"\\"+QUARTZ_FILE_NAME;
InputStream quartzPropertiesInputStream = null;
try {
quartzPropertiesInputStream = new FileInputStream(quartzPropertiesFileName);
} catch (FileNotFoundException e) {
if(logger != null)
logger.error("Failed to open quartz properties input stream: "+quartzPropertiesFileName, e);
throw new Exception();
}
try {
quartzProperties.load(quartzPropertiesInputStream);
} catch (IOException e) {
if(logger != null)
logger.error("Failed to load quartz properties file: "+quartzPropertiesFileName, e);
throw new Exception();
}
quartzProperties.put("org.quartz.plugin.jobInitializer.fileNames", configsFolder+"\\"+QUARTZJOBS_FILE_NAME);
try {
quartzPropertiesInputStream.close();
} catch (IOException e) {
if(logger != null)
logger.error("Failed to close quartz properties input stream: "+quartzPropertiesFileName, e);
throw new Exception();
}
OutputStream quartzPropertiesOutputStream = null;
try {
quartzPropertiesOutputStream = new FileOutputStream(quartzPropertiesFileName);
} catch (FileNotFoundException e) {
if(logger != null)
logger.error("Failed to open quartz properties output stream: "+quartzPropertiesFileName, e);
throw new Exception();
}
try {
quartzProperties.store(quartzPropertiesOutputStream, "");
} catch (IOException e) {
if(logger != null)
logger.error("Failed to save quartz properties file: "+quartzPropertiesFileName, e);
throw new Exception();
}
try {
quartzPropertiesOutputStream.close();
} catch (IOException e) {
if(logger != null)
logger.error("Failed to close quartz properties output stream: "+quartzPropertiesFileName, e);
throw new Exception();
}
/*------------- Here, I begin to create scheduler ---------------------*/
StdSchedulerFactory factory = null;
try {
factory = new StdSchedulerFactory(configsFolder+"\\"+QUARTZ_FILE_NAME);
} catch (SchedulerException e) {
if(logger != null)
logger.error("Quartz return an error while " +
"reading it properties file: "+configsFolder+"\\"+QUARTZ_FILE_NAME, e);
throw new Exception();
}
Scheduler scheduler = null;
try {
scheduler = factory.getScheduler();
} catch (SchedulerException e) {
if(logger != null)
logger.error("Quartz factory failed to create scheduler", e);
throw new Exception();
}
}
quartz.properties :
Code:
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = #### THIS FIELD IS DYNAMICALLY UPDATED BY INITCONFSERVLET ####
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 3600
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
I've kept
Code:
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
to avoid tomcat from freezing while shuting down, it looks like it was the problem.
|
 |
|
|
Hi,
I'm using JobInitializerPlugin to start my jobs. Until now, I was loading both files, quartz.properties and jobs.xml, from WEB-INF/classes and that worked fine.
But I want to organize a little more my project, and move configuration files to WEB-INF/conf by specifing new folder in the web.xml file.
For log4j, no problem, i've wrote :
Code:
<context-param>
<param-name>log4j-properties-location</param-name>
<param-value>conf/log4j.properties</param-value>
</context-param>
and it works.
So I've try the same for quartz :
Code:
<servlet>
<servlet-name>
QuartzInitializer
</servlet-name>
...
<init-param>
<param-name>config-file</param-name>
<param-value>conf/quartz.properties</param-value>
</init-param>
...
</servlet>
and the file can't be found until I write the whole file path.
Same inside *.properties files, log4j.properties can understand : Code:
log4j.appender.file.File = ${catalina.home}/logs/ESSOReporting.log
But it is impossible to find jobs.xml using :
Code:
org.quartz.plugin.jobInitializer.fileNames = ${basedir}/WebContent/WEB-INF/quartz_jobs.xml
Which also work with full file path.
${basedir} is read as part of the string and not as a variable.
How can I configure quartz to work in a none static location without polluting my WEB-INF/classes with it ?
Best Regards,
onemore.
|
 |
|
|
Great, thanks !
So, here is a link that i've found to conclude on this topic.
Modification of xml file:
http://www.mkyong.com/java/how-to-modify-xml-file-in-java-jdom/
Regards, onemore.
|
 |
|
|
can I have informations about the scanInterval capability ?
My application is based on one job with one trigger, but the execution period must be modifiable by the user through my web interface by sending a formular.
switch(cycle){
case 'daily': cron = '0 0 '+hour+' * * ?'; break;
case 'weekly': cron = '0 0 '+hour+' ? * SUN'; break;
case 'monthly': cron = '0 0 '+hour+' 1 * ?'; break;
}
To update the execution pediod, if I change the period of the cron trigger inside the jobs.xml file.
For example,
replacing Code:
<cron-expression>0 0 0 ? * SUN</cron-expression>
by Code:
<cron-expression>0 0 0 1 * ?</cron-expression>
.
Will the application be updated automatically ?
I suppose that it will, so what is the best way to modify the xml file ? is their methods implemented for it, or should I use a xml parser ?
|
 |
|
|
Hi,
I'm using jobInitializer to start my Job, it's look like a good idea as it is possible to setup a scan interval :
"org.quartz.plugin.jobInitializer.scanInterval = 10"
My job must be configurable at any time during the application's life, I wanted to know how could I update dynamically the trigger inside the jobs.xml file ?
how can I modify information inside my jobs.xml file ?
Regards,
onemore.
|
 |
|
|
|
|