Skip to main content

Simple Variable Language

The org.apache.juneau.commons.svl package defines an API for a language called "Simple Variable Language" (SVL) — text that contains variables of the form $varName{varKey}. Variables can be recursively nested and can return values that themselves contain more variables.

See the guide: Externalize config with INI/YAML and variables

VarResolver.DEFAULT ships the following built-in source variables:

VariableDescription
$S{key[,default]}Java system property (System.getProperty).
$E{key[,default]}OS environment variable (System.getenv).
$EF{key[,default]}Key from a .env-style env file on the filesystem.
$DE{key[,default]}Key from a .env dotenv file (same format, alternative naming).
$A{key[,default]}Command-line argument passed to the JVM.
$MF{key[,default]}Entry from the classpath META-INF/MANIFEST.MF.
$P{key[,default]}Unified Settings source stack — consults system properties, env vars, classpath juneau.cfg, per-microservice Config, Spring Environment, and more in priority order.
${key:default}Shorthand for $P{key,default}. The Spring-style : default separator is rewritten to , before delegation.
Example
// Resolve a system-property variable.
String home = VarResolver.DEFAULT.resolve("Java home: $S{java.home}");

// Nested fallback chain: env var → system property → literal default.
String val = VarResolver.DEFAULT.resolve("$E{MY_VAR,$S{my.var,not found}}");

// Spring-style ${...} shorthand against the unified Settings stack.
String title = VarResolver.DEFAULT.resolve("${myapp.title:Untitled}");

#{...} Function-call Syntax​

Alongside $Var{...} style variables, SVL supports a #{name(args...)} function-call syntax backed by a catalog of ~68 built-in functions across 10 categories:

CategoryExample functions
Stringupper, lower, trim, substring, split, join, format, pathToken
Type conversiontoInt, toLong, toDouble, toBoolean, toString
Arithmeticadd, sub, mul, div, mod, min, max, abs, round
Booleannot, and, or, eq, ne
Conditionalif, switch, coalesce, notEmpty, case
Regexmatches, replace, extract
EncodingurlEncode, urlDecode, base64Encode, base64Decode, htmlEscape
Date/timenow, today, formatDate, parseDate
Random/UUIDuuid, randomInt, randomString
JSON navigationjsonPath, get, keys, values, size

This syntax replaces 11 dedicated transformation Var classes ($UC{}, $IF{}, $SW{}, etc.) that were removed in 10.0 in favor of the unified function library.

Example
VarResolver.DEFAULT.resolve("#{upper(hello world)}");                      // → "HELLO WORLD"
VarResolver.DEFAULT.resolve("#{if(${prod:false}, prod-key, dev-key)}"); // → "dev-key"
VarResolver.DEFAULT.resolve("#{switch(${tier:bronze}, gold:1.0, *:0)}"); // → "0"
VarResolver.DEFAULT.resolve("#{uuid()}"); // → a random UUID

User code can add custom functions via VarResolver.create().functions(MyFunction.class).build() or via ServiceLoader discovery in META-INF/services/org.apache.juneau.commons.svl.VarFunction.

VarTemplate Compiled-Template API​

VarResolver.compile(input) tokenizes a template once and returns a reusable VarTemplate. This skips re-tokenization on every resolve call — useful at framework injection sites or anywhere the same template is resolved repeatedly.

// Compile once (e.g. at startup or in framework metadata).
VarTemplate tpl = VarResolver.DEFAULT.compile("hello ${user.name:guest}");

// Resolve many times without re-parsing.
String s = tpl.resolve(VarResolver.DEFAULT.createSession());

VarResolver.resolveSupplier(input) wraps this into a thread-safe Supplier<String> that opens a fresh session on every .get(), which pairs naturally with @Value Supplier<String> field injection for live-reload patterns.

SVL variables are used widely throughout Juneau annotations, allowing many features to be configured from external sources such as configuration files, environment variables, or system properties.

See Also
  • Marshall Simple Variable Language for marshall-side SVL usage — the marshall-context variables, resolvers, and default resolver that build on the language described here. This page remains the canonical SVL language reference.
  • SVL Security for the security guidance on exposing variables to untrusted input.