开发者

Read system properties from file specified as java executable argument

By launching java with the -D option you can set System.properties.

Is there a way to specify a properties file as an option for java, which in turn read them as System.properties?

E.g.

java -Dfile ./alotof.properties

I'm building a webapp deployed in JBoss. The jboss xml configuration files accepts system properties as inline config {my.property}, which reads from the command line a开发者_StackOverflowrgument but this gets unruly as the number of properties grow.


You can read the properties file in bash (in run.sh file), parse properties and create the proper config line for JVM.

Here you can find 2 articles that can help you:

  • Reading Java-style Properties Files with Shell (permalink)
  • Reading java.properties file from bash


I don't know about giving a direct property file as an argument, but instead you can have startup class which loads at the bootstrap and overrides whatever property you want override from your property file using System.setProperty() method.


Java can't read system properties from a file, but JBoss can - use the SystemPropertiesService, configured through properties-service.xml in the deploy directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜