简体   繁体   中英

Executing shell script containing java -jar Runtime.exec(), which java will it take, OS level or application level

I am trying to execute a java jar from my jmeter tests via beanshell.

The approach I followed is to create a shell script, execute it through beanshell using Runtime.exec() function.

The question I have is whether execution of this shell script will take java from instance/host/OS level or it will be executed as part of current java that the application is using.

There could be open questions for which I want to provide an answer to before time:

  1. I have a maven project, in which I specify java.
  2. The build runs the jmeter script which has beanshell executing the jar file.
  3. I also do some processing with the output of the jar execution(write specific output to another file, hence I wrote the shell script).
  4. I use this specific output, and use it to add to my request in jmeter before querying.

Any help is appreciated.

In a way, both.

The shell script will be executed as part of your Java program, but it will be executed using the system's default Java executable unless you've specified a Java executable in the exec() method call.

Depending on how you run your application. If you just use

Runtime.getRuntime().exec("java -jar ...."); 

The Process instance will look for java executable which is available in your OS PATH . If there will no be java executable in the PATH - the call will fail.


Be aware that starting from JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language for any form of scripting so consider migrating to Groovy on next available opportunity. For instance you can kick off the process and get the output as simple as:

String response = "your command".execute().text

Also instead of running your .jar in as separate process it might be better to add it to JMeter Classpath and call necessary functions directly from the Groovy code. See Apache Groovy - Why and How You Should Use It article for more information.

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