How to run a jar file from Jmeter?

2019-09-09 22:51发布

问题:

I tried the following in the Bean Shell Sampler;

Runtime rt = Runtime.getRuntime();
rt.exec("cmd.exe /c && cd /Program Files/Java/jdk1.8.0_51/jre/bin & java -jar File-2.0-SNAPSHOT.WAR");

It looks like, it is not able to run.. Am i doing in the correct way?

回答1:

If you need to do it with Beanshell, I would suggest the following amendment to the process command line:

cmd /c start java -jar .....

See cmd.exe documentation for more information

However in majority of cases it might be easier to use OS Process Sampler which allows executing arbitrary commands and programs. Check out How to Run External Commands and Programs Locally and Remotely from JMeter