我正在使用Apache POI读取Excel文件,它在本地计算机(独立编)上运行良好,但未在服务器(IBM Websphere)上运行。遇到实例化WorkBook时,它停止工作。
使用下面的罐子。
commons-codec-1.5.jar poi-3.9.jar poi-examples-3.9.jar poi-ooxml-3.9.jar poi-ooxml-schemas-3.9.jar xmlbeans-2.6.0.jar
下面是我的代码:
String mountInFilePath = "//XXXXX/YY/Foooo/folder/";
File fileList = new File(mountInFilePath);
File[] fileNames = fileList.listFiles();
String inFileName = null;
if(fileNames != null && fileNames.length > 1){
throw new Exception("Multiple Files found in "+mountInFilePath+", Please place the latest one.");
}else{
System.out.println("getAbsolutePath: "+fileList.getAbsolutePath());
for(File file : fileNames){
System.out.println("New file path: "+file.getCanonicalPath());
inFileName = file.getCanonicalPath();
}
}
LOGGER.info("File: "+inFileName);
if(inFileName != null){
LOGGER.info("Inside IF cond...");
System.out.println("Inside IF cond...");
//Getting the workbook file
LOGGER.info("After FileInputStream...");
File chkAcc = new File(inFileName);
if(chkAcc.canRead()){
LOGGER.info("File Readable.."); //This is printed
}else{
LOGGER.info("Can not read file..");
}
Workbook workbook = WorkbookFactory.create(chkAcc); //Stopped here
//Iterating work sheet
LOGGER.info("Iterating...");
System.out.println("Iterating...");
答案 0 :(得分:0)
一次检查这些依赖项jar是否确实包含在最终版本中(您已在服务器中部署了一个)。我在Weblogic服务器中遇到了此类问题,在构建.ear文件时我错过了将jar包含在内
答案 1 :(得分:0)
现在已解决。我错过了向pom.xml添加一个依赖项,但是它在我的构建路径中。正如Deepak Gunasekaran在回答中提到的那样,添加后解决了。我也升级到了3.15版本。