简体   繁体   中英

Exception in thread “main” java.lang.NullPointerException at org.apache.jmeter.engine.StandardJMeterEngine.configure(StandardJMeterEngine.java:176)

I'm trying to run Jmeter test plan via java and below is the code,

package com.jmeter;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;
import java.io.FileInputStream;
public class JMeterFromExistingJMX {
    public static void main(String[] argv) throws Exception {
        // JMeter Engine
        StandardJMeterEngine jmeter = new StandardJMeterEngine();
        // Initialize Properties, logging, locale, etc.

        JMeterUtils.loadJMeterProperties("c:\\JMeter\\apache-jmeter-3.0\\bin\\jmeter.properties");
        JMeterUtils.setJMeterHome("c:\\JMeter\\apache-jmeter-3.0");
        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
        FileInputStream in = new FileInputStream("c:\\JMeter\\apache-jmeter-3.0\\extras\\Test.jmx");
        HashTree testPlanTree = SaveService.loadTree(in);
        in.close();
        // Run JMeter Test
        jmeter.configure(testPlanTree);
        jmeter.run();
    }
}

and below are .jars files I've added in my classpath, Classpath Libraries

While Compiling the aforementioned code, I'm getting below exception,

INFO 2017-01-28 20:25:58.549 [jmeter.e] (): Listeners will be started after enabling running version INFO 2017-01-28 20:25:58.572 [jmeter.e] (): To revert to the earlier behaviour, define jmeterengine.startlistenerslater=false

Exception in thread "main" java.lang.NullPointerException
    at org.apache.jmeter.engine.StandardJMeterEngine.configure(StandardJMeterEngine.java:176)
    at com.jmeter.JMeterFromExistingJMX.main(JMeterFromExistingJMX.java:32)
  1. Upgrade to the latest JMeter version (3.1 as of now), JMeter 2.6 is 5+ years old
  2. According to the Five Ways To Launch a JMeter Test without Using the JMeter GUI article

    To execute an existing JMeter test from Java code or to create one through programming, basic Java knowledge is a must, and the following are mandatory:

    1. Have JMeter installed somewhere
    2. Have the required JMeter jars from /lib and especially /lib/ext folders of your JMeter installation in your project or module class path.

    so you need to remove apachejmeter_core-2.6.jar and add the libraries from the latest JMeter version installation folder instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM