51Testing软件测试论坛

标题: jmeter 执行第三方的jar包执行错误 [打印本页]

作者: 小丫头amy    时间: 2016-6-23 15:10
标题: jmeter 执行第三方的jar包执行错误


我自己写了一个java程序,程序如下,通过eclipse调用方法是正确的(备注:这个java程序中引入了第三方的poi的jar包)
  1. package com.luqiao.test;

  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import javax.swing.JOptionPane;

  9. //下面是和数据导出有关的包
  10. import org.apache.poi.xssf.usermodel.XSSFCell;
  11. import org.apache.poi.xssf.usermodel.XSSFCellStyle;
  12. import org.apache.poi.xssf.usermodel.XSSFRow;
  13. import org.apache.poi.xssf.usermodel.XSSFSheet;
  14. import org.apache.poi.xssf.usermodel.XSSFWorkbook;

  15. public class ExportExcel {
  16.         private static String filepath = "E://aa.xlsx";
  17.         public static XSSFCell cell;
  18.         public static XSSFRow row;
  19.         public static FileInputStream ExcelFile;
  20.         public static XSSFSheet  sheet;
  21.         public static XSSFWorkbook wb;

  22.         public static  void Export(int rowNo, int colNo, String result, boolean isHeader, List<String> header) throws Exception {
  23.                
  24.                 ExcelFile=new FileInputStream(filepath);
  25.                
  26.                  wb = new XSSFWorkbook(ExcelFile);
  27.                  sheet = wb.getSheet("aa");
  28.                   sheet.setDefaultColumnWidth(15);
  29.        

  30.                 if (isHeader) {
  31.                        
  32.                         if(sheet.getRow(rowNo)==null){
  33.                                 row=sheet.createRow(0);
  34.                                
  35.                         }
  36.                        
  37.                         else {
  38.                                 row=sheet.getRow(0);
  39.                         }

  40.                         for (int i = 0; i < header.size(); i++) {
  41.                                 XSSFCell cell = row.getCell(i);
  42.                                 cell.setCellValue(header.get(i));
  43.                                
  44.                                

  45.                         }
  46.                 }
  47.                
  48.                 if(sheet.getRow(rowNo)==null){
  49.                         row=sheet.createRow(rowNo);
  50.                        
  51.                 }
  52.                
  53.                 else {
  54.                         row=sheet.getRow(rowNo);
  55.                 }
  56.                  
  57.                  //如果单元格是空,就返回null
  58.                  cell=row.getCell(colNo,row.RETURN_BLANK_AS_NULL);
  59.                  if(cell==null){
  60.                          cell=row.createCell(colNo);
  61.                          cell.setCellValue(result);
  62.                          
  63.                  }
  64.                  else {cell.setCellValue(result);}

  65.                 try {
  66.                         // 默认导出到E盘下
  67.                         FileOutputStream os=new FileOutputStream(filepath);
  68.                          wb.write(os);
  69.                          os.flush();
  70.                          os.close();
  71.                        
  72.                 } catch (FileNotFoundException e) {
  73.                         e.printStackTrace();
  74.                 } catch (IOException e) {
  75.                         e.printStackTrace();
  76.                 }
  77.         }
  78.        
  79.         public static  String getCellData(int rowNo,int colNo) throws Exception {
  80.        
  81.                  row=sheet.getRow(rowNo);
  82.                  cell=row.getCell(colNo);
  83.                  String cellData=cell.getCellType()==XSSFCell.CELL_TYPE_STRING?cell.getStringCellValue():
  84.                          String.valueOf(Math.round(cell.getNumericCellValue()));
  85.                  return cellData;       
  86.         }
  87.          public static void main (String []args) throws Exception{
  88.              boolean flag=false;
  89.              String tel="13205920075";
  90.              for(int i=0;i<50;i++){
  91.              //System.out.println(tel);
  92.              List<String> list=new ArrayList<String>();
  93.              
  94.              Export(i, 0, tel, flag, list);
  95.              Export(i, 1, "123456", flag, list);
  96.              //System.out.println(exportdata.getCellData(i, 0)+""+exportdata.getCellData(i, 1) );
  97.              }
  98.               
  99.       }
  100. }
复制代码
把上面的程序打包成jar包后,放到jmeter的bin/lib/ext目录下,然后调用方法getCellData的时候就会报错,报错信息如下:org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval        Sourced file: inline evaluation of: ``import com.luqiao.test.*; import java.io.FileInputStream; import java.io.FileNot . . . '' : Method Invocation data1.getCellData

只要我写的java程序引入第三方的jar包,jmeter调用的时候都报如上的错误,找不到什么原因。求大神们指导?





作者: 狂梦乱静    时间: 2016-7-2 14:27
我也同问
作者: 小丫头amy    时间: 2016-7-6 16:36
狂梦乱静 发表于 2016-7-1 22:27
我也同问

上次听我同事说可以用maven将依赖的jar也一起打包成jar包。




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2