JMeter 3.3与JMeter Maven插件2.6.0命令行执行故障求助
Hey there, let's tackle your two issues one by one—both are common pitfalls when upgrading JMeter and using the Maven plugin, so let's dive in:
Issue 1: HTTPS Connection Refused (HTTP works fine)
The fact that HTTP requests succeed but HTTPS ones fail tells me there's a key difference between how GUI and command-line/JMeter Maven plugin handle SSL or core dependencies. Here are the most impactful fixes:
Possible Causes & Fixes:
- Missing Required JMeter Dependencies
Looking at your pom, you’ve excludedcommons-math3:commons-math3—but JMeter 3.3 relies heavily on this library for core functionality, including SSL connection handling. When running via GUI, your local JMeter installation probably has this dependency already, but the Maven plugin builds an isolated classpath without it, breaking HTTPS connections.
- Fix: Remove the
<exclusion>commons-math3:commons-math3</exclusion>entry from yourexcludedArtifactslist.
- SSL Protocol Mismatch
JMeter 3.3 updated default SSL protocols compared to the old 2.3 version. If your target server only supports older protocols (like TLSv1 instead of TLSv1.2), the command-line mode might fail while GUI works (if you manually adjusted settings there).
- Fix: Add these lines to your
jmeter.propertiesfile:
Then, tell the Maven plugin to use this config by addinghttps.default.protocol=TLSv1.2 https.socket.protocols=TLSv1,TLSv1.1,TLSv1.2<jmeterPropertiesFile>path/to/your/jmeter.properties</jmeterPropertiesFile>inside the plugin’s<configuration>section.
- Un-Trusted SSL Certificates
If your target uses a self-signed or internal CA certificate, the GUI might have cached the trust, but the command-line/Maven plugin doesn’t inherit this.
- Fix: Import the certificate into JMeter’s truststore:
Then, ensure the Maven plugin uses this truststore by adding system properties to the plugin config:keytool -import -alias your-server -file /path/to/cert.crt -keystore $JMETER_HOME/bin/cacerts -storepass changeit<systemProperties> <javax.net.ssl.trustStore>/path/to/your/jmeter/bin/cacerts</javax.net.ssl.trustStore> <javax.net.ssl.trustStorePassword>changeit</javax.net.ssl.trustStorePassword> </systemProperties>
- Firewall/Network Restrictions
Sometimes command-line processes have stricter firewall rules than GUI apps. Test if you can reach the HTTPS port from the command line:
telnet your-hostname 443
If this fails, adjust your firewall to allow the Maven/JMeter process access to port 443.
Issue 2: Maven-Passed Parameters Not Working in JMeter
The users, duration, and other parameters not being picked up usually comes down to mismatched property names or conflicting dependencies. Let’s fix this:
Possible Causes & Fixes:
- Correct
__PFunction Usage
In your pom, you map Maven’s${Users}to JMeter’susersproperty via<users>${Users}</users>. In JMeter, the__Pfunction requires a default value to avoid nulls if the property isn’t set.
- Fix: In your JMeter test plan, use
${__P(users, 10)}(where 10 is your default number of users) instead of just${__P(users)}. Apply the same pattern to other parameters:- Hostname:
${__P(host, default-host.com)} - Port:
${__P(port, 443)}
- Hostname:
- Remove Manual JMeter Dependencies
You’ve addedApacheJMeter_coreandApacheJMeter_javaas direct dependencies, but the JMeter Maven plugin already manages these. This can cause version conflicts or classpath issues that break property passing.
- Fix: Remove the entire
<dependencies>section from your pom—let the plugin handle JMeter dependencies automatically.
- Verify Property Passing with Debug Logs
To confirm if properties are reaching JMeter, run Maven with debug logging:
mvn verify -X -DUsers=50 -DhostName=your-server.com -DportNumber=443
Look for lines like Setting user property: users=50 in the logs. If you don’t see these, double-check your pom’s propertiesUser section is correctly nested inside <configuration>.
- UDV Configuration Fix
If you’re using User Defined Variables (UDV), make sure you reference JMeter properties correctly. For example, set the UDV’s "users" variable value to${__P(users, 10)}—don’t just typeusersor leave it blank.
Final Pom Adjustments Summary
Here’s a trimmed-down version of your pom with key fixes applied:
<modelVersion>4.0.0</modelVersion> <groupId>com.abcd.efg</groupId> <artifactId>app-Performance-Test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <build> <plugins> <plugin> <groupId>com.lazerycode.jmeter</groupId> <artifactId>jmeter-maven-plugin</artifactId> <version>2.6.0</version> <executions> <execution> <id>jmeter-tests</id> <phase>verify</phase> <goals> <goal>jmeter</goal> </goals> </execution> </executions> <configuration> <generateReports>true</generateReports> <scanResultsForSuccessfulRequests>true</scanResultsForSuccessfulRequests> <scanResultsForFailedRequests>true</scanResultsForFailedRequests> <downloadOptionalDependencies>false</downloadOptionalDependencies> <resultsDirectory>/path/report</resultsDirectory> <!-- Add SSL truststore config if needed --> <systemProperties> <javax.net.ssl.trustStore>/path/to/your/jmeter/bin/cacerts</javax.net.ssl.trustStore> <javax.net.ssl.trustStorePassword>changeit</javax.net.ssl.trustStorePassword> </systemProperties> <!-- Reference jmeter.properties with SSL settings --> <jmeterPropertiesFile>/path/to/your/jmeter.properties</jmeterPropertiesFile> <propertiesUser> <host>${hostName}</host> <port>${portNumber}</port> <users>${Users}</users> <duration>${duration}</duration> <rampup>${rampUp}</rampup> <datafile>${test.data}</datafile> </propertiesUser> <jmeterExtensions> <artifact>kg.apc:jmeter-plugins-casutg:2.4</artifact> </jmeterExtensions> <testResultsTimestamp>false</testResultsTimestamp> <excludedArtifacts> <!-- Removed commons-math3 exclusion --> <exclusion>commons-pool2:commons-pool2</exclusion> <exclusion>org.slf4j:slf4j-nop</exclusion> <exclusion>logkit:logkit</exclusion> <exclusion>avalon-logkit:avalon-logkit</exclusion> <exclusion>jdom:jdom</exclusion> <exclusion>log4j:log4j</exclusion> <exclusion>commons-logging:commons-logging</exclusion> <exclusion>excalibur-logger:excalibur-logger</exclusion> </excludedArtifacts> </configuration> </plugin> </plugins> </build>
Try these steps one by one—start with fixing dependencies and property references, as those are the most likely culprits. If you still run into issues, share the debug logs from Maven and we can dig deeper!
内容的提问来源于stack exchange,提问作者user1480332

