0

I would like to get a reference ServletContext from a Quartz job to access a file from my own web application properties in the WEB-INF folder but I'm newbie with Quartz Scheduler and I can not.

The file is in: /WEB-INF/mypreferences.properties and want to read from the Quartz job.

I'm using Eclipse Java EE and Quartz Scheduler 2.2.1.

My web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>My Web Application</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <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>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <context-param>
        <param-name>quartz:config-file</param-name>
        <param-value>quartz.properties</param-value>
    </context-param>
</web-app>

My Job Quartz:

public class MyJob implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //Get ServletContext reference and read the properties file my own web application
    }
}
Jorge Alvarado
  • 57
  • 1
  • 1
  • 8
  • You would have to pass it in using the `JobDataMap`. – Andreas Oct 10 '15 at 16:09
  • I want to read my application preferences (mypreferences.properties), not the preferences of Quartz (quartz.properties). Also I mentioned that I am new in Quartz and do not understand that are the JobDataMap. – Jorge Alvarado Oct 10 '15 at 16:40
  • See http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/more-about-jobs.html#jobdatamap – Andreas Oct 10 '15 at 18:36

0 Answers0