cron join quartz schedule spring Jahia 8 Jahia 7.3

How to add a cron job


What is the way to schedule a job in Jahia?


First, you need to create your Job class that extends the  QuartzJobBean. Here is a basic example of Job that does nothing except displaying a message on debug mode.  Note that we get some external data from the spring.

package package;

import org.quartz.JobDataMap;
import org.slf4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.List;

public class MyJob extends QuartzJobBean {
    private transient static Logger logger = org.slf4j.LoggerFactory.getLogger(MyJob.class);

     * Execute the actual job. The job data map will already have been
     * applied as bean property values by execute. The contract is
     * exactly the same as for the standard Quartz execute method.
     * @see #execute
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        logger.debug("Executing job here...");

        // get the jobDataAsMap from spring file
        JobDataMap mergedJobDataMap = context.getMergedJobDataMap();
        String var1 = (String) mergedJobDataMap.get("var1");
        logger.debug("var1=" + var1);
        String var2 = (String) mergedJobDataMap.get("var2");
        logger.debug("var2=" + var2);
        String var3 = (String) mergedJobDataMap.get("var3");
        logger.debug("var3=" + var3);
        List<String> otherVarAsList = (List<String>) mergedJobDataMap.get("otherVarAsList");
        logger.debug("otherVarAsList=" + otherVarAsList.toString());

And then you need to create an XML spring file in the resources/META-INF/spring directory. In this example, some properties are set using the jobDataAsMap property. 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
    <bean parent="jobSchedulingBean">
        <property name="ramJob" value="false"/>
        <property name="trigger">
            <bean class="org.quartz.CronTrigger">
                <property name="name" value="ReferentielJobTrigger"/>
                <!-- Will start the process at 4 a.m -->
                <property name="cronExpression" value="${sitemapCronExpression:0 0 4 * * ?}"/>
        <property name="jobDetail">
            <bean class="org.springframework.scheduling.quartz.JobDetailBean">
                <property name="name" value="myJob"/>
                <property name="group" value="MyGroup"/>
                <property name="jobClass" value=""/>
                <property name="description" value="This is the description of the Job" />
                <property name="jobDataAsMap">
                        <entry key="var1" value="value1" />
                        <entry key="var2" value="value2" />
                        <entry key="var3" value="value3" />
                        <entry key="otherVarAsList">

Once it's deployed, you should be able to view the job on the Job Administration (from the tools /modules/tools/jobadmin.jsp)


and the related details when we click on the info icon.


Note that this Job is a non ramJob  (the value is set to false (default value).

<property name="ramJob" value="false"/>

It means that this Job is persistent and is only executed on the processing server. If you want to schedule a job on each cluster nodes, then you will need to set the value to true.

<property name="ramJob" value="true"/>