Skip to main content

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:

ConfiggetSystemDefault()setSystemDefault(Config)

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:

  1. If the system property (or environment variable) juneau.configFile is set, it is the only candidate — no other names are considered.
  2. Otherwise:
    1. If the JVM was launched from a jar file (i.e. sun.java.command ends in .jar), two jar-name-derived candidates are added first: the jar's base file name with a .cfg extension (e.g. myapp-1.0.cfg), followed by that same base name with any trailing ./_-delimited version suffix stripped (e.g. myapp.cfg).
    2. Every file in the current/working directory whose name ends in .cfg is added next, in whatever order the JVM's File.listFiles() returns them for that directory — this is filesystem/OS-dependent and is not guaranteed to be alphabetical.
    3. Finally, the following fixed fallback names are added, in this order: juneau.cfg, default.cfg, application.cfg, app.cfg, settings.cfg, application.properties.

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.