0

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)
Parthi
  • 1
  • 1
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Grzegorz Oledzki Jan 28 '17 at 16:10

1 Answers1

0
  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.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks for your suggestion. But even after doing the aforementioned as well, getting the same error – Parthi Jan 31 '17 at 07:15