Search code examples
javagradlequartz

How do I specify a quartz property file outside of the classpath in gradle?


I'm attempting to specify my quartz properties file in gradle. From a 'config' directory rather than from resources.

String quartzProperties = System.properties['org.quartz.properties'] ?: "file:config/local/quartz.properties"
System.setProperty("org.quartz.properties", quartzProperties)

The output from

(System.properties).each {
    println "Prop ${it}"
}

or the properties task, is

Prop quartz.properties=file:config/local/quartz.properties

The output from quartz is

PropertiesFactoryBean      --- Loading properties file from class path resource [quartz.properties]
SchedulerConfig$$EnhancerB --- Cannot load quartz.properties.

The symptom of it not being set is that I am getting the wrong sql dialect so the application gives a database error on load.


Solution

  • I had the same question and looking at your code, using file:config/local/quartz.properties was wrong most likely. The official docs really only put a path into that property, without any URI-prefix or whatsoever. That prefix most likely made the path invalid and Quartz was unable to find it. The following is an example from GitHub:

    workdir=`dirname $0`
    workdir=`cd ${workdir} && pwd`
    QUARTZ=${workdir}/../..
    [...]
    # Set the name and location of the quartz.properties file
    QUARTZ_PROPS="-Dorg.quartz.properties=${workdir}/quartz.properties"
    

    At least one available factory really only uses a file as well:

        String requestedFile = System.getProperty(PROPERTIES_FILE);
        String propFileName = requestedFile != null ? requestedFile
                : "quartz.properties";
        File propFile = new File(propFileName);
    

    Besides that, at least nowadays some factories exist which support providing settings directly:

    StdSchedulerFactory(Properties props)
    Create a StdSchedulerFactory that has been initialized via initialize(Properties).
    
    initialize(InputStream propertiesStream)
    Initialize the SchedulerFactory with the contents of the Properties file opened with the given InputStream.