Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing an entire file to JVM arguments

I have several systems that all need to load the same properties to the JVM. I can use the -D flag to load one property at a time, but i am looking for something that will load all the properties in an entire file at one time. For instance:

I could just add --options-file=blah.properties to all jvms on my network, once, and from then on only change the properties file, which could be a single central file over a network share.

Thank you,

EDIT: Any arguments or commands must also work in a windows environment. Therefore any bash or scripting hacks specific to unix will not work.

like image 455
doug Avatar asked Feb 01 '11 18:02

doug


People also ask

How do I pass multiple VM arguments in IntelliJ?

Configure JVM options From the main menu, select Help | Edit Custom VM Options. If you do not have any project open, on the Welcome screen, click Configure and then Edit Custom VM Options. If you cannot start IntelliJ IDEA, manually copy the default file with JVM options to the IntelliJ IDEA configuration directory.

How do I set JVM arguments in Eclipse?

-- Go to the Eclipse Window > preferences, in "Java > Installed JREs". -- Copy the current default JRE with a new name, for example myJRE. -- Select the new JRE and click on the "Edit" button. -- In the "Edit JRE" dialog, add your JVM arguments in the "Default VM Arguments" field.


2 Answers

That's roughly how we do it:

java $(tr '\n' ' ' < options_file) other args...

Here options_file contains ready -Dsomething or -Xsomething values, one per line. The tr command just replaces every newline with a space.

like image 106
9000 Avatar answered Sep 23 '22 02:09

9000


I don't think you can do that via the command line (without some bash hacks, perhaps), but you definitely can do that programatically:

Simply set one property -DmyPropertiesFile=/your/properties/file.properties and then read that with one of the Properties.load() overloads. After that, System.setProperties(yourProps) should do what you expect.

Of course, this requires that you can hook this code early enough so that your properties will be available when needed (For instance, if the main() method is yours, this is perfect).

like image 26
Costi Ciudatu Avatar answered Sep 22 '22 02:09

Costi Ciudatu