我正在使用application
插件来运行我的应用程序。我想像这样设置一个属性prop
-Dprop="some value"
为此,我在build.gradle
applicationDefaultJvmArgs = ["-Dprop=$prop"]
我的build.gradle
看起来像这样
apply plugin: 'application'
mainClassName='my.package.Main'
run {
// allows to run application { gradle run -Pdocument=["file.xml"] }
if (project.hasProperty("document")) {
args groovy.util.Eval.me(document)
}
}
dependencies {
compile ("org.apache.poi:poi:$apachePoiVersion")
compile ("org.apache.poi:poi-ooxml:$apachePoiVersion")
}
applicationDefaultJvmArgs = ["-Dprop=$prop"]
在我的Main
应用程序中,我尝试显示它以检查它是否已设置
try (ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("spring-context.xml")) {
LOGGER.info("System property prop: [{}].", System.getProperty("prop"));
}
但它显示System property prop: [null]
。
我像这样启动应用程序
gradle run -Pprop="D://my-folder"
属性-Pdocument="['']"
正常工作。有什么问题?