简体   繁体   English

jmeter中如何使用java类?

[英]How to use java class in jmeter?

I have tried running java class in jmeter. 我试过在jmeter中运行Java类。
I have placed java code in BSF preprocessor. 我已经将Java代码放在BSF预处理器中。
But the following error occurred: 但是发生以下错误:

ERROR - org.apache.bsf.BSFManager: Exception : java.lang.ClassNotFoundException: org.apache.bsf.engines.java.JavaEngine
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190

I have tried this link for including jar file. 我已经尝试过此链接以包含jar文件。 But i dont know which jar file i need to include. 但是我不知道我需要包含哪个jar文件。

Can some one tell me which jar file include for running java class in jmeter? 有人可以告诉我在jmeter中包含哪个jar文件来运行Java类吗?

It is better to use Beanshell instead of Java. 最好使用Beanshell而不是Java。

There seems to be a packaging issue in BSF, see BSF中似乎存在包装问题,请参见

In the meantime, you can get a binary distribution with all BSF engines for BSF 2.4 (as well as a slightly advanced version of BSF 2.4) from http://wi.wu-wien.ac.at/rgf/rexx/bsf4rexx/current/BSF4Rexx_install.zip . 同时,您可以从http://wi.wu-wien.ac.at/rgf/rexx/bsf4rexx/获得用于BSF 2.4(以及BSF 2.4的稍微高级版本)的所有BSF引擎的二进制发行版。 current / BSF4Rexx_install.zip After unpacking that zip-archive, you will find a jar-file named "bsf-v244-20080704.jar". 解压缩该zip归档文件后,您将找到一个名为“ bsf-v244-20080704.jar”的jar文件。 Just replace the official BSF 2.4 with that version (which contains all official engines as well as "BSF_Log" and "BSF_LogFactory"). 只需用该版本替换正式的BSF 2.4(包含所有正式引擎以及“ BSF_Log”和“ BSF_LogFactory”)。

The mentionned jar also has some issues. 提到的罐子也有一些问题。

Anyway for performance and up to date code, it is better to use JSR223 Sampler + Groovy + fill in Compilation Cache Key 无论如何,为了获得性能和最新代码,最好使用JSR223 Sampler + Groovy +填写Compilation Cache Key

Which versoin of jmeter are you using? 您正在使用jmeter的哪个版本? With 2.9 jsr 223 pre-processor using java language is working fine for me. 使用Java语言的2.9 jsr 223预处理器对我来说工作正常。 I think the jsr223-* elements are superseding beanchell-* and BSF-* elements so you can give it a try. 我认为jsr223- *元素取代了beanchell- *和BSF- *元素,因此您可以尝试一下。

java and beanshell btw are claimed slow if you have it executed a lot. 如果执行很多,则声称Java和beanshell btw速度很慢。 You can use groovy and JSR223 preprocesor. 您可以使用groovy和JSR223预处理程序。 You can see about caching the compiled code in the JSR223 sampler docs. 您可以在JSR223采样器文档中看到有关缓存已编译代码的信息

Beanshell and groovy are mostly java code compatible so you can use java code with them but not entirely. Beanshell和groovy大多数都是Java代码兼容的,因此您可以将Java代码与其一起使用,但不能完全使用。 Anything more complicated in pure java can fail to compile in groovy and/or beanshell. 纯Java中任何更复杂的东西都可能无法在Groovy和/或beanshell中进行编译。

If you use pure java, then it makes sense to use the Java Request sampler if you can instead of a pre-processor. 如果使用纯Java,则可以使用Java Request采样器代替预处理器。 If technically hard to achieve, the fastest option seems to use groovy with jsr223 pre-processor and caching the compiled code. 如果在技术上难以实现,最快的选择似乎是将groovy与jsr223预处理程序结合使用并缓存已编译的代码。

Hope this helps. 希望这可以帮助。

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

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