0

I have JMeter '.jmx' file.

Can I run it using Java? If yes, please let me know how to do it or share any good link

Anand
  • 20,708
  • 48
  • 131
  • 198
  • I believe you can find your answer here: http://stackoverflow.com/questions/19147235/how-to-create-and-run-apache-jmeter-test-scripts-from-a-java-program – DanielM Apr 07 '14 at 07:35
  • @cheseaux - i did try but could only found the link provided by style in the comment after you – Anand Apr 07 '14 at 07:37
  • @style - in that link, it is told how to create the requests and all. I already have the requests created in .jmx file. I only need to run that file – Anand Apr 07 '14 at 07:38
  • Are you kidding me ? First link I've found was the official documentation : https://jmeter.apache.org/usermanual/get-started.html#running, there is your answer. – cheseaux Apr 07 '14 at 07:40
  • 1
    @cheseaux: Nope, because apparently he wants to run it from a Java program, not from the command line. – Michael Borgwardt Apr 07 '14 at 09:54
  • It would help if you better described what you are trying to do. Since JMeter is a Java program, the short answer is yes and a pointer to the jmeter home page. I assume that is not what you want. – kc2001 Apr 16 '14 at 12:18

2 Answers2

2

The class org.apache.jmeter.NewDriver has the main() method that the application is started with. You can call it programmatically and pass it the appropriate arguments (like -t test.jmx). You probably have to construct the test plan specifically to yield usable results if you want it to run without a GUI, though.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
  • I am not able to get it working. Can you please provide me the code snippet regarding what needs to do to run test.jmx – Anand Apr 07 '14 at 09:46
  • Did you say that I do something like this NewDriver.main(), here I pass '-t test.jmx'? – Anand Apr 07 '14 at 09:56
  • @Anand: yes, though you may have to pass each part of the parameters separately (parameter type is String[]) – Michael Borgwardt Apr 07 '14 at 10:53
  • I tried NewDriver.main(new String[]{"C:\\Users\\Anand.Jain\\Desktop\\hits.jmx"}); but it is giving me An error occurred: Unknown arg: C:\Users\Anand.Jain\Desktop\hits.jmx. – Anand Apr 08 '14 at 07:07
  • It is not looking in actual Jmeter directory and hence giving me these exceptions as well java.lang.Throwable: Could not access C:\workspace\learn\lib at org.apache.jmeter.NewDriver.(NewDriver.java:99) at JmeterTest1.main(JmeterTest1.java:9) java.lang.Throwable: Could not access C:\workspace\learn\lib\ext at org.apache.jmeter.NewDriver.(NewDriver.java:99) at JmeterTest1.main(JmeterTest1.java:9) java.lang.Throwable: Could not access C:\workspace\learn\lib\junit at org.apache.jmeter.NewDriver.(NewDriver.java:99) at JmeterTest1.main(JmeterTest1.java:9) – Anand Apr 08 '14 at 07:08
  • @Anand: you have to pass in the parameters as you would pass them to JMeter on the command line, so at minimum -t before the test file, and probably also -n to show no GUI. Look at the documentation for more. And of course you have to set the appropriate class path to include the JMeter JARs when you start your Java program. – Michael Borgwardt Apr 08 '14 at 07:14
1

It's quite simple:

jmeter -t test.jmx
znurgl
  • 1,077
  • 7
  • 12