1.创建工程,新建类,HelloWorld.java,代码如下:
  1 package com.liuke;
  2
  3 
  4
  5 public class HelloWorld {
  6
  7    public String getHello(){
  8
  9       return "调用自定义函数getHello()";
  10
  11    }
  12
  13    public static void main(String[] args) {
  14
  15       System. out .println("恭喜你调用静态main函数成功");
  16
  17    }
  18
  19 }
  2、导出jar包并命名为HelloWorld.jar
  3、将新生成的jar包HelloWorld.jar放到一个指定的目录下,如D:LoadRunnerjar。
  4、新建Virtual User:选Java Vuser


  5、导入jar包文件HelloWorld.jar,Run-time Settings--classpath加入HelloWorld.jar。
  6、写脚本,代码如下:
  1 import lrapi.lr;
  2
  3 import com.lkf.HelloWorld;
  4
  5 
  6
  7 public class Actions
  8
  9 {
  10
  11 
  12
  13              public int init() throws Throwable {
  14
  15                 return 0;
  16
  17              }//end of init
  18
  19              public int action() throws Throwable {
  20
  21                  //调用自定义函数getHello()
  22
  23                 HelloWorld h = new HelloWorld();
  24
  25                 System.out.println(h.getHello());
  26
  27                 //调用静态系统main函数
  28
  29                 HelloWorld.main(null);
  30
  31                 return 0;
  32
  33              }//end of action
  34
  35              public int end() throws Throwable {
  36
  37                 return 0;
  38
  39              }//end of end
  40
  41 }
  7、运行脚本结果,看到如下输出结果,说明脚本运行成功了
  System. out:调用自定义函数getHello()
  System. out:恭喜你调用静态main函数成功