2

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 argument but this gets unruly as the number of properties grow.

Reddy
  • 8,737
  • 11
  • 55
  • 73
aelgn
  • 821
  • 1
  • 11
  • 17
  • you can possibly write a simple class that reads the file and uses System.setProperty; or just change the starting script (bash/bat/etc) and read the properties on your own. – bestsss Jan 31 '11 at 16:24

3 Answers3

1

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.

GuruKulki
  • 25,776
  • 50
  • 140
  • 201
1

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:

Community
  • 1
  • 1
Lukasz Stelmach
  • 5,281
  • 4
  • 25
  • 29
1

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

Tom Anderson
  • 46,189
  • 17
  • 92
  • 133