使用JMeter(Bean Shell)运行Java类 [英] Running Java class with JMeter (Bean Shell)

查看:489
本文介绍了使用JMeter(Bean Shell)运行Java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个Java类,供JMeter使用,将项目打包为.jar文件,然后将该文件移到jmeter目录中的lib/ext文件夹中.我看过有关如何进行的文档,但它们给出了矛盾的答案.

I have written a Java Class for use in JMeter, packaged the project as a .jar file and moved that file into the lib/ext folder in the jmeter directory. I have seen documentation on how to proceed but they give contradictory answers.

第一种方法是使用BeanShell Sampler导入我的包和类,创建该类的对象并以这种方式运行方法.与示例类相比,我已经使用了这种方法,该类具有比我要运行的类更简单的文件结构.示例类与以下BeanShell脚本一起使用.

The first way is to use the BeanShell Sampler to import my package and class, create an object of the class and run the methods that way. I have used this method using example classes with more simple file structures than that of class I want to run. The example classes work with the following BeanShell script.

import tools.JmeterTools;
JmeterTools jt = new JmeterTools();
jt.foo();

当我尝试对要运行的类使用此方法时,它指出变量声明是错误的,并且找不到该类.我认为这是因为我不知道要确切导入什么,因为我项目中的文件结构有点奇怪.

When I try to use this method for the class I want to run, it states that the variable declaration is an error and the Class cannot be found. I assume this is because I do not understand what to import exactly, as the file structure in my project is a little odd.

第二个使用BeanShell PreProcessor将jar添加到类路径.我根本无法使用这种方法,但是已经阅读了很多其他有关成功的文章.它的工作方式如下:

The second uses the BeanShell PreProcessor to add the jar to the class path. This method I have not been able to get to work at all, but have read many accounts of others finding success. It works as follows:

addClassPath("directory path to jar\lib\ext\foo.jar");
JMeterTest jtm = new JMeterTest();
jmt.test();

有人会知道哪种方法会更好,或者关于如何解决导入问题的任何想法吗?

Would anyone have any knowledge of which way would work better or any ideas on how to fix the import?

我在BeanShell脚本中一直使用的导入如下:

The import I have been using in the BeanShell script is the following:

import client.JMeterTest;

我的课程顶部的包装行如下

The package line at the top of my class is the following

import com.x.foo.client;

推荐答案

面向以后遇到此问题的任何人.其他人给出的答案是正确的.它对我不起作用,因为我忘记了在制作jar时Maven不会将文件打包在测试目录中.

For anyone who has this issue in the future. The answers given by others are correct. It wasn't working for me because I had forgotten that Maven does not package files in the test directory when a jar is made.

如果将来有人这样做,此链接可能会有所帮助. 在测试包中生成测试jar和jar文件

This link may help if anyone ever does this in the future. Generate test-jar along with jar file in test package

这篇关于使用JMeter(Bean Shell)运行Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆