Forum Discussion

chaton's avatar
chaton
New Contributor
13 years ago

JAR in [LoadUI Home]/ext Not Recognized by Script Runner

I have put the JAR file providing the class com.cybersoft4u.stress.util.ExcelHelper in /ext folder under LoadUI installation directory. But the Script Runner always reports the error bellow.

Script1.groovy: 25: unable to resolve class com.cybersoft4u.stress.util.ExcelHelper
@line 25, column 1.
import com.cybersoft4u.stress.util.ExcelHelper
^
1 error

The class above refers to Apache POI jars, which have been downloaded in place by Grapes. The ExcelHelper is wriiten by Groovy as follow. Is there anything I have missed to have the Script Runner to load the JAR for reference?

package com.cybersoft4u.stress.util

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import org.apache.poi.poifs.filesystem.POIFSFileSystem

class ExcelHelper {
private HSSFWorkbook wb;
private HSSFSheet sheet;
public ExcelHelper(String fileName){
InputStream is = new FileInputStream(fileName)
POIFSFileSystem fs;
try {
fs = new POIFSFileSystem(is);
this.wb = new HSSFWorkbook(fs);
this.sheet = wb.getSheetAt(0);
} catch (IOException e) {
e.printStackTrace();
}
}

String getCell(HSSFCell cell){
def value = null
switch(cell.getCellType()){
case HSSFCell.CELL_TYPE_NUMERIC:
value = String.valueOf(cell.getNumericCellValue())
break
case HSSFCell.CELL_TYPE_STRING:
value = cell.getRichStringCellValue().getString().trim()
break
}
return value
}

String[] getRandomData(){
def total = this.sheet.getLastRowNum()+1
def random = new Random()
def ranNum = random.nextInt(total)
String[] rowData = getRowData(ranNum);
while(rowData==null){
ranNum = random.nextInt(total)
rowData = getRowData(ranNum);
}
return rowData
}

String[] getRowData(int rowIndex){
HSSFRow row = this.sheet.getRow(rowIndex)
String[] rowData = new String[row.getLastCellNum()]
for(int i=0; i<rowData.length; i++){
rowData = getCell(row.getCell(i))
}
return rowData
}

public static void main(String[] args) {
ExcelHelper helper = new ExcelHelper("test.xls")
System.out.println(helper.getRandomData())
}
}

1 Reply

  • peskums's avatar
    peskums
    New Contributor

    Hi,

    Am looking for a similar solution, I am facing issues with POI jars in Load UI, Which run absolutely fine from SOAP UI. but errors out from Load UI.

    Did you get a solution for your issue, if so please share me the work around.

     

    Thanks

    Kumarswamy