aelgn
aelgn

Reputation: 900

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

Upvotes: 3

Views: 4619

Answers (3)

Lukasz Stelmach
Lukasz Stelmach

Reputation: 5381

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:

Upvotes: 1

Tom Anderson
Tom Anderson

Reputation: 47173

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

Upvotes: 1

GuruKulki
GuruKulki

Reputation: 26418

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.

Upvotes: 1

Related Questions