如何在gradle中指定类路径之外的quartz属性文件?

时间:2017-10-26 02:08:56

标签: java gradle quartz

我试图在gradle中指定我的quartz属性文件。来自' config'目录而不是资源。

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

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

或属性任务是

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

石英的输出是

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

没有设置的症状是我得到了错误的sql方言,因此应用程序在加载时会出现数据库错误。

1 个答案:

答案 0 :(得分:1)

我有同样的问题,看着您的代码,使用file:config/local/quartz.properties很可能是错误的。官方文档实际上只在该属性中添加了一条路径,没有任何URI前缀或任何前缀。该前缀很可能使路径无效,并且Quartz无法找到它。以下是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"

至少有一个可用的factory实际上也只使用一个文件:

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

此外,至少在some factories年代,这种语言支持直接提供设置:

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.