skip to content

In JMeter, what does the -G flag do with an argument that contains no equals sign?

level: seniorimportance: nice to knowfreq 19%

answer

  1. One flag, two argument shapes
  2. The absent equals sign is the switch
  3. A readability check with no else branch
  4. No log line is the only signal

basics

~20 s

JMeter reads the whole argument as a path to a properties file and loads every key in it into the global property set. If that path cannot be read, JMeter does nothing and logs nothing.

solid answer

~40 s

`-G` is the one property flag with two argument shapes. `-Gport=123` defines a single global property; `-Gglobal.properties`, with no `=`, names a file whose entire contents become global properties. The parser supplies an empty second argument when there is no equals sign, and `JMeter.initializeProperties` branches on exactly that: a non-empty value means `setProperty`, an empty one means treat the first argument as a path. That file branch is guarded by `propFile.canRead()` and has **no else**, so a path that is missing, misspelled or unreadable produces no error, no warning and no INFO line at all — the run simply starts with an empty global set. `-q` and `-S` both warn when their file is missing, which makes `-G` the odd one out and worth checking deliberately. Apache JMeter 6.0.0.

go deeper

for a junior

Just know that -G accepts either a name=value pair or a bare file name, and that the documented usage text shows both spellings. That alone stops you writing the file form and expecting a property named after the file.

for a middle

Explain the switch: the parser fills in an empty second argument when there is no equals sign, and JMeter branches on the empty value to decide between setting one property and loading a whole file.

for a senior

Point at the operational hazard: the file branch is guarded by a readability check with no else, so a wrong path leaves no trace. Say how you would catch it — absolute paths, and asserting on the Setting Global properties from the file line.

for a principal

Treat silent configuration failures as a class rather than a bug to remember. Decide what evidence a run must produce before its results are accepted, so a value that never arrived cannot pass as a value that did.

`-G` is the only property flag in JMeter with two argument shapes, and it decides between them by looking at whether the argument contained an equals sign. ## How the two shapes are told apart JMeter's parser declares `-G` with `ARGUMENTS_REQUIRED_2`, so it always wants a name and a value. When the argument has no `=`, the parser reaches the end of that token and fills the missing second argument with an empty string. `JMeter.initializeProperties` then branches on exactly that: ```java case JMETER_GLOBAL_PROP -> { if (!value.isEmpty()) { // -Gport=123 log.info("Setting Global property: {}={}", name, value); remoteProps.setProperty(name, value); } else { // -Gglobal.properties File propFile = new File(name); if (propFile.canRead()) { log.info("Setting Global properties from the file {}", name); try (FileInputStream fis = new FileInputStream(propFile)) { remoteProps.load(fis); } catch (...) { ... } } } } ``` Both shapes are documented: the built-in usage text shows `-Gport=123` and `-Gglobal.properties` as alternatives under the same flag. ## The silent branch Look at the `else` arm again. The whole file load is wrapped in `if (propFile.canRead())`, and there is **no else**. If the path is misspelled, relative to the wrong working directory, or unreadable because of permissions, JMeter: - writes no error; - writes no warning; - writes not even an INFO line; - carries on and starts the run with an empty global property set. That is unusual behaviour for this family of flags, and the contrast is worth memorising: | Flag | Missing file | |---|---| | `-q file` | `WARN Can't find additional property file: ...` | | `-S file` | `WARN Cannot find system property file. ...` | | `-G file` | nothing at all | | `-p file` | run aborts, `Could not read JMeter properties file:...` | ## How to catch it The positive log line is your only signal, so assert on it. A successful load prints: ``` INFO o.a.j.JMeter: Setting Global properties from the file ./config/production-globals.properties ``` If that line is absent from `jmeter.log`, the file was not read. Two habits make this cheap: pass an absolute path rather than one relative to whatever directory the job happened to start in, and have the job fail if the expected line is missing before it accepts the results. ## A related shape to watch The same empty-second-argument rule means a bare `-Gbase.url` — someone meaning `-Gbase.url=https://...` and losing the tail to a shell quoting mistake — is not an error either. JMeter takes `base.url` as a **file name**, cannot read it, and does nothing. The flag you thought you passed simply evaporated. For one plan pointed at staging and then production, that is exactly the failure you cannot afford: the run happens, the samples are recorded, and the only evidence that the environment override never arrived is a log line that was never written. Behaviour described is Apache JMeter 6.0.0.

  • How do -q and -S behave when their file is missing?
    Both complain. -q logs `Can't find additional property file:` at WARN and carries on without those keys; -S logs `Cannot find system property file.` at WARN. Only -G's file branch is silent, because it tests canRead() first and does nothing when the test fails.
  • What does a bare -Gbase.url, with the value lost to a shell quoting mistake, actually do?
    Nothing. The empty second argument sends it down the file branch, JMeter treats base.url as a file name, cannot read it, and skips it without a message. The property you meant to define simply never exists, and no artefact from the run records the attempt.

saying these in an interview costs you the question

  • Says -G only accepts name=value form
  • Expects a missing -G file to abort the run
  • Confuses -G's file form with the -q flag
  • Assumes -G warns about an unreadable path
  • Trusts a relative -G path in a scheduled job