skip to content

What does JMeter's -p flag replace, and what does -q add on top of it?

level: middleimportance: should knowfreq 34%

answer

  1. One replaces, the other layers
  2. Only one of the two is repeatable
  3. Their missing-file behaviour is not the same
  4. One is handled before the flag loop runs

basics

~10 s

JMeter's -p names the base property file to load instead of bin/jmeter.properties and may appear only once. -q names an extra property file merged on top of the current set, and may be repeated.

solid answer

~40 s

`-p file` replaces the base file: `JMeter.initializeProperties` calls `JMeterUtils.loadJMeterProperties` with your path instead of `<jmeter home>/bin/jmeter.properties`, so every default that file would have supplied becomes yours to provide. It is registered without `DUPLICATES_ALLOWED`, so a second `-p` is rejected with `Error: Duplicate options for -p/--propfile found.` `-q file` is different: it loads the file into a temporary `Properties` and does `putAll` into the set already built, so it merges and overrides, it is repeatable, and it is applied at the position it holds among the other property flags. The failure modes differ too — an unreadable `-q` path logs a warning and the run continues, while an unreadable `-p` path aborts with `Could not read JMeter properties file:` and exit status 1. Apache JMeter 6.0.0.

code

bash · 7 lines
bash
# -p REPLACES the base file; an unreadable path aborts the run with exit 1
jmeter -n -t checkout.jmx -l run.jtl -p ./config/base.properties

# -q MERGES on top and may be repeated; a missing file only warns
jmeter -n -t checkout.jmx -l run.jtl \
  -q ./config/common.properties \
  -q ./config/production.properties

go deeper

for a junior

Recall which flag is which: -p for the base property file, -q for an additional one. Knowing that -q is the safe everyday choice will keep you out of trouble on a first headless run.

for a middle

Explain the mechanics: -p swaps the file loaded at the very start, -q does a putAll over the set already built, and only -q is repeatable. Note that -p means you now own every default the standard file supplied.

for a senior

Show the failure modes matter operationally: a bad -q path warns and the run continues short of those keys, while a bad -p path kills the process with exit status 1. Say which of those you would rather a scheduled job hit.

for a principal

Set the team's default. For most fleets that is bin/jmeter.properties plus one -q file per environment, with -p reserved for a purpose-built image whose base configuration is deliberately self-contained and owned.

`-p` and `-q` both take a path to a `.properties` file, and that is where the similarity ends. One replaces JMeter's base property file; the other layers an extra file on top of whatever is already loaded. ## -p replaces the base file `JMeter.initializeProperties` begins with a single decision: ```java if (parser.getArgumentById(PROPFILE_OPT) != null) { JMeterUtils.loadJMeterProperties(parser.getArgumentById(PROPFILE_OPT).getArgument()); } else { JMeterUtils.loadJMeterProperties(NewDriver.getJMeterDir() + "/bin/jmeter.properties"); } ``` Your file is loaded **instead of** `bin/jmeter.properties`, not alongside it. Every key the default file would have supplied is now your responsibility. Two further details follow from the descriptor. `-p` is registered with `ARGUMENT_REQUIRED` and **not** `DUPLICATES_ALLOWED`, so a second `-p` on the same command line is rejected before anything runs, with `Error: Duplicate options for -p/--propfile found.` followed by the usage text. And the failure mode is hard: `JMeterUtils.loadJMeterProperties` falls back to a classpath resource named `org/apache/jmeter/jmeter.properties`, which the Apache distribution does not ship, so an unreadable path ends in `RuntimeException: Could not read JMeter properties file:<path>`. `JMeter.start` catches it, prints `An error occurred: Could not read JMeter properties file:...` and calls `System.exit(1)`. A typo in a `-p` path stops the run; it does not quietly downgrade it. ## -q adds a file on top `-q` is handled inside the same loop that processes `-J`, `-D`, `-G`, `-S` and `-L`: ```java case PROPFILE2_OPT -> { log.info("Loading additional properties from: {}", name); try (FileInputStream fis = new FileInputStream(name)) { Properties tmp = new Properties(); tmp.load(fis); jmeterProps.putAll(tmp); } catch (FileNotFoundException e) { log.warn("Can't find additional property file: {}", name, e); } } ``` The differences that matter: - **It merges.** `putAll` copies the file's keys over the current set, so `-q` overrides what is already there and leaves everything else alone. - **It is repeatable.** The descriptor carries `DUPLICATES_ALLOWED`, so you can layer a common file and an environment file in one command. - **It is positional.** Being inside the ordered loop, a `-q` is applied where it sits relative to the `-J` flags around it. - **It fails soft.** A missing file logs `Can't find additional property file:` at WARN and the run continues, short those keys. ## Side by side | | `-p` | `-q` | |---|---|---| | Effect | replaces the base file | merges on top | | Repeatable | no, duplicate is rejected | yes | | Position matters | no, handled first | yes, applied in place | | Missing file | run aborts, exit status 1 | warning, run continues | ## Which to reach for For one plan pointed at staging and then at production, `-q` is almost always the right flag: ship `staging.properties` and `production.properties`, each holding only the handful of keys that differ, and let `bin/jmeter.properties` continue to supply everything else. Reach for `-p` only when you genuinely want a self-contained base configuration under your own control — a container image with its own curated property file, for instance — and accept that you now own every default that file no longer inherits. Behaviour described is Apache JMeter 6.0.0.

  • What happens if you pass -p twice on one command line?
    The command line is rejected before anything runs. -p is declared without DUPLICATES_ALLOWED, so the parser raises a duplicate-option error and JMeter prints `Error: Duplicate options for -p/--propfile found.` followed by the usage text instead of starting a test. -q carries DUPLICATES_ALLOWED and can be repeated freely.
  • If -q merges on top, what does it merge on top of?
    Whatever the JMeter property set holds at the moment that flag is reached in the startup pass — which includes the base file and any earlier command-line option. Because the pass walks the options in the order you typed them, a later -q overrides an earlier one, and an earlier -J.

saying these in an interview costs you the question

  • Says -p adds a file alongside the default one
  • Thinks -q replaces the base property file
  • Expects a wrong -p path to fall back quietly
  • Believes -q can only be given once per run
  • Assumes both flags fail the same way on a missing file