无法使用Groovy从Eclipse运行java代码到Jmeter
下面的代码打印excel文件中的内容(在eclipse中尝试过),但我无法使用Groovy在Jmeter 3.1中运行它 我抛出了一个错误: JSR223脚本JSR223采样器中存在问题,消息: javax.script.ScriptException: org.codehaus.groovy.control.multipleCompationerErrorSexception: 启动失败 这是我的代码:无法使用Groovy从Eclipse运行java代码到Jmeter,groovy,jmeter,Groovy,Jmeter,下面的代码打印excel文件中的内容(在eclipse中尝试过),但我无法使用Groovy在Jmeter 3.1中运行它 我抛出了一个错误: JSR223脚本JSR223采样器中存在问题,消息: javax.script.ScriptException: org.codehaus.groovy.control.multipleCompationerErrorSexception: 启动失败 这是我的代码: public static void main (String args[]) throw
public static void main (String args[]) throws IOException
{
GetExcelTableInto2DArrayListString("C:\\Users\\val1\\Desktop\\Book1.xlsx", true);
}
public static void GetExcelTableInto2DArrayListString(String excelFile, boolean debug) throws IOException{
ArrayList<String> OUT = new ArrayList<String>();
File myFile = new File(excelFile);
FileInputStream fis = null;
fis = new FileInputStream(myFile);
String columnWanted = "PhysicalIDs";
Integer columnNo = null;
XSSFWorkbook myWorkBook = null;
myWorkBook = new XSSFWorkbook (fis);
// Return first sheet from the XLSX workbook
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
// Get iterator to all the rows in current sheet
List<Cell> cells = new ArrayList<Cell>();
Row firstRow = mySheet.getRow(0); //rowIterator.next();
for(Cell cell:firstRow){
if (cell.getStringCellValue().equals(columnWanted)){
columnNo = cell.getColumnIndex();
}
}
System.out.println(columnNo);
DataFormatter formatter = new DataFormatter(Locale.US);
if (columnNo != null){
for (Row row : mySheet) {
Cell c = row.getCell(columnNo);
System.out.println(formatter.formatCellValue(c));
if (c == null) {
// Nothing in the cell in this row, skip it
} else {
cells.add(c);
}
}
}else{
System.out.println("could not find column " + columnWanted + " in first row of " + myFile.toString());
}
}
publicstaticvoidmain(字符串args[])引发IOException
{
GetExcelTableInto2ArrayListString(“C:\\Users\\val1\\Desktop\\Book1.xlsx”,true);
}
公共静态void getExcelTableInto2ArrayListString(字符串excelFile,布尔调试)引发IOException{
ArrayList OUT=新的ArrayList();
文件myFile=新文件(excelFile);
FileInputStream fis=null;
fis=新文件输入流(myFile);
字符串columnWanted=“PhysicalIDs”;
整数columnNo=null;
XSSFWorkbook myWorkBook=null;
myWorkBook=新XSSFWorkbook(fis);
//返回XLSX工作簿中的第一张工作表
XSSFSheet mySheet=myWorkBook.getSheetAt(0);
//获取当前工作表中所有行的迭代器
列表单元格=新的ArrayList();
Row firstRow=mySheet.getRow(0);//rowditerator.next();
用于(单元格:第一行){
if(cell.getStringCellValue().equals(columnWanted)){
columnNo=cell.getColumnIndex();
}
}
系统输出打印项次(列号);
DataFormatter formatter=新的DataFormatter(Locale.US);
if(columnNo!=null){
用于(行:mySheet){
单元格c=行。获取单元格(列号);
System.out.println(formatter.formatCellValue(c));
如果(c==null){
//此行单元格中没有任何内容,请跳过它
}否则{
添加(c);
}
}
}否则{
System.out.println(“在“+myFile.toString()”的第一行中找不到“+columnWanted+”列);
}
}
我强烈怀疑您的代码是否能在eclipse(无论是什么)和其他任何地方工作,因为这行代码:
public static void main (String args[])
在Java和Groovy中都不是语法正确的
入口点的“良好”声明(尽管Groovy脚本不需要它)是:
public static void main(String[] args)
完整代码以防万一:
import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.DataFormatter
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.xssf.usermodel.XSSFSheet
import org.apache.poi.xssf.usermodel.XSSFWorkbook
public static void main(String[] args) throws IOException {
GetExcelTableInto2DArrayListString("C:\\Users\\val1\\Desktop\\Book1.xlsx", true);
}
public static void GetExcelTableInto2DArrayListString(String excelFile, boolean debug) throws IOException {
ArrayList<String> OUT = new ArrayList<String>();
File myFile = new File(excelFile);
FileInputStream fis = null;
fis = new FileInputStream(myFile);
String columnWanted = "PhysicalIDs";
Integer columnNo = null;
XSSFWorkbook myWorkBook = null;
myWorkBook = new XSSFWorkbook(fis);
// Return first sheet from the XLSX workbook
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
// Get iterator to all the rows in current sheet
List<Cell> cells = new ArrayList<Cell>();
Row firstRow = mySheet.getRow(0); //rowIterator.next();
for (Cell cell : firstRow) {
if (cell.getStringCellValue().equals(columnWanted)) {
columnNo = cell.getColumnIndex();
}
}
System.out.println(columnNo);
DataFormatter formatter = new DataFormatter(Locale.US);
if (columnNo != null) {
for (Row row : mySheet) {
Cell c = row.getCell(columnNo);
System.out.println(formatter.formatCellValue(c));
if (c == null) {
// Nothing in the cell in this row, skip it
} else {
cells.add(c);
}
}
} else {
System.out.println("could not find column " + columnWanted + " in first row of " + myFile.toString());
}
}
import org.apache.poi.ss.usermodel.Cell
导入org.apache.poi.ss.usermodel.DataFormatter
导入org.apache.poi.ss.usermodel.Row
导入org.apache.poi.xssf.usermodel.xssfheet
导入org.apache.poi.xssf.usermodel.xssf工作簿
公共静态void main(字符串[]args)引发IOException{
GetExcelTableInto2ArrayListString(“C:\\Users\\val1\\Desktop\\Book1.xlsx”,true);
}
公共静态void getExcelTableInto2ArrayListString(字符串excelFile,布尔调试)引发IOException{
ArrayList OUT=新的ArrayList();
文件myFile=新文件(excelFile);
FileInputStream fis=null;
fis=新文件输入流(myFile);
字符串columnWanted=“PhysicalIDs”;
整数columnNo=null;
XSSFWorkbook myWorkBook=null;
myWorkBook=新XSSFWorkbook(fis);
//返回XLSX工作簿中的第一张工作表
XSSFSheet mySheet=myWorkBook.getSheetAt(0);
//获取当前工作表中所有行的迭代器
列表单元格=新的ArrayList();
Row firstRow=mySheet.getRow(0);//rowditerator.next();
用于(单元格:第一行){
if(cell.getStringCellValue().equals(columnWanted)){
columnNo=cell.getColumnIndex();
}
}
系统输出打印项次(列号);
DataFormatter formatter=新的DataFormatter(Locale.US);
if(columnNo!=null){
用于(行:mySheet){
单元格c=行。获取单元格(列号);
System.out.println(formatter.formatCellValue(c));
如果(c==null){
//此行单元格中没有任何内容,请跳过它
}否则{
添加(c);
}
}
}否则{
System.out.println(“在“+myFile.toString()”的第一行中找不到“+columnWanted+”列);
}
}
更多信息:
import org.apache.poi.ss.usermodel.Cell import org.apache.poi.ss.usermodel.DataF…”遇到了“导入”“在第2行第1列。在线评估:
import org.apache.poi.ss.usermodel.Cell import org.apache.poi.ss.usermodel.DataF…“”在第2行“很可能您没有库,您需要下载并将其复制到JMeter安装的“lib”文件夹中。重新启动JMeter以获取.jar。更多信息: