chaton
14 years agoNew Contributor
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())
}
}
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())
}
}