简体   繁体   English

执行包含Java -jar Runtime.exec()的shell脚本,它将使用Java,OS级别或应用程序级别

[英]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. 我试图通过beanshell从我的jmeter测试中执行一个Java jar。

The approach I followed is to create a shell script, execute it through beanshell using Runtime.exec() function. 我遵循的方法是创建一个Shell脚本,并使用Runtime.exec()函数通过beanshell执行该脚本。

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. 我的问题是执行此Shell脚本是否将从实例/主机/操作系统级别获取Java,还是将其作为应用程序正在使用的当前Java的一部分执行。

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. 我有一个Maven项目,其中指定了Java。
  2. The build runs the jmeter script which has beanshell executing the jar file. 该构建运行jmeter脚本,该脚本具有执行jar文件的beanshell。
  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). 我还对jar执行的输出进行了一些处理(将特定输出写入另一个文件,因此我编写了shell脚本)。
  4. I use this specific output, and use it to add to my request in jmeter before querying. 我使用此特定输出,并在查询之前将其用于添加到jmeter中的请求中。

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. Shell脚本将作为Java程序的一部分执行,但是除非您在exec()方法调用中指定了Java可执行文件,否则它将使用系统的默认Java可执行文件exec()

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 . Process实例将查找java可执行文件,该文件在您的OS PATH中可用。 If there will no be java executable in the PATH - the call will fail. 如果PATH中没有java可执行文件-调用将失败。


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. 请注意, 从JMeter 3.1开始,建议对任何形式的脚本使用JSR223测试元素和Groovy语言 ,因此请考虑在下一个可用机会时迁移到Groovy。 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. 另外,与其将.jar作为单独的进程运行,不如将其添加到JMeter Classpath并直接从Groovy代码中调用必要的函数可能更好。 See Apache Groovy - Why and How You Should Use It article for more information. 有关更多信息,请参见Apache Groovy-为什么和如何使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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