1
votes

I am trying to run jmeter through java. The examples from https://www.blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui

I uploaded jmx file like was described in example.

In the jmx file I have properties. Properties specified like ${__property(0_users,,0)}

I manged to upload this property through command line using -J parameter.

How can I specify parameters through java. I didn't find any info regarding this.

Does exist some way to specify it directly in java ? StandardJMeterEngine jmeter = new StandardJMeterEngine();

    // Initialize Properties, logging, locale, etc.
    JMeterUtils.loadJMeterProperties("C:\\jMeter\\apache-jmeter-2.13\\bin\\jmeter.properties");
    JMeterUtils.setJMeterHome("C:\\jMeter\\apache-jmeter-2.13");

    JMeterUtils.initLogging();// you can comment this line out to see extra log messages of i.e. DEBUG level
    JMeterUtils.initLocale();

    // Initialize JMeter SaveService
    SaveService.loadProperties();

    // Load existing .jmx Test Plan
    File jmxFile = new File("C:\\jMeter\\test.jmx");
    HashTree testPlanTree = SaveService.loadTree(jmxFile);

    jmeter.configure(testPlanTree);
    jmeter.run();
1

1 Answers

0
votes

The aforementioned link states:

// Initialize Properties, logging, locale, etc
JMeterUtils.loadJMeterProperties("/path/to/your/jmeter/bin/jmeter.properties");

So you can define the properties you need directly in jmeter.properties or user.properties files - they live in Jmeter's "bin" folder like:

0_users=50
foo=bar

And finally you always have possibility to fall back to Java Properties. If you plan to create a Java executable you can switch to __Beanshell() function like:

${__BeanShell(System.getProperty("0_users"))}

Property value can be provided via -D command line argument like:

your_binary -D0_users=50

or again you can set the value via system.properties file.

Remember that you need to have ApacheJMeter_functions.jar library in your CLASSPATH in order to properly evaluate any JMeter function.

See Apache JMeter Properties Customization Guide for comprehensive information on using JMeter properties.