System Default Config
Each JVM has a system default config. This is a configuration file that serves as the default configuration for the system. It's accessed using the following static methods:
If you do not specify a system default config, one will be automatically searched for, using the candidate names returned by Config.getCandidateSystemDefaultConfigNames(). Each candidate name is looked up first as a file in the current/working directory (the directory the JVM was launched from), and then as a classpath resource; the first candidate that resolves to either is used as the system default.
The candidate names are built in the following order:
- If the system property (or environment variable)
juneau.configFileis set, it is the only candidate — no other names are considered. - Otherwise:
- If the JVM was launched from a jar file (i.e.
sun.java.commandends in.jar), two jar-name-derived candidates are added first: the jar's base file name with a.cfgextension (e.g.myapp-1.0.cfg), followed by that same base name with any trailing./_-delimited version suffix stripped (e.g.myapp.cfg). - Every file in the current/working directory whose name ends in
.cfgis added next, in whatever order the JVM'sFile.listFiles()returns them for that directory — this is filesystem/OS-dependent and is not guaranteed to be alphabetical. - Finally, the following fixed fallback names are added, in this order:
juneau.cfg,default.cfg,application.cfg,app.cfg,settings.cfg,application.properties.
- If the JVM was launched from a jar file (i.e.
Later in the section on REST resources, we describe how to associate configurations with REST resources using the @Rest(config) annotation.
The system default configuration can be referenced with the keyword SYSTEM_DEFAULT like so:
// Always use system default.
@Rest(config="SYSTEM_DEFAULT")
// Use system property if set or the system default if not.
@Rest(config="$S{juneau.configFile,SYSTEM_DEFAULT}")
By default, all properties in the system default configuration are automatically set as system properties.
This can be disabled by setting the system property juneau.disableAutoSystemProps to true.