I'm receiving an error when trying to create an XSSFWorkbook
Code
currentCharterTemplate = 'UnusedTicketsWorkbook.xlsx';
currentFilePath = getDirectoryFromPath(getCurrentTemplatePath());
javaFile = createObject('java', 'java.io.File').init(currentFilePath & currentCharterTemplate);
excelFile = createObject('java', 'java.io.FileInputStream').init(javaFile);
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook');
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook').init(excelFile);
I also tried just the line below and I receive the same error.
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook');
Error
cannot load class through its string name, because no definition for the class with the specified name
[org.apache.poi.xssf.usermodel.XSSFWorkbook] could be found caused by (java.lang.ClassNotFoundException:org.apache.poi.xssf.usermodel.XSSFWorkbook;
java.lang.ClassNotFoundException:org.apache.poi.xssf.usermodel.XSSFWorkbook not found by lucee.core [46];)
I've installed the cfspreadsheet extension for Lucee, and restarted Lucee and my computer, I've verified cfspreadsheet-3.0.1.jar
is available in C:\lucee\tomcat\lucee-server\bundles
along with all the other jar files included with lucee.
If I open the jar with 7-zip, I can see poi-ooxml-3.15.jar
is included. Within that jar I can browse to C:\lucee\tomcat\lucee-server\bundles\cfspreadsheet-3.0.1.jar\poi-ooxml-3.15.jar\org\apache\poi\xssf\usermodel\XSSFWorkbook.class
The lucee.core
in the error message makes me think it's not recognizing jars from my extensions, but I can't find a setting to enable this.
I just tested your code and it seems that the OSGI bundle from the extension isn't actually loaded until you actually hit the cfspreadsheet tag at least once. Once I run the cfspreadsheet tag, the cfspreadsheet bundle in the server admin shows as active and then createObject()
can find the class.
// Force Lucee to activate the bundle
spreadsheet action="read" src="#expandPath( 'UnusedTicketsWorkbook.xlsx' )#" name="test";
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook');
I also just figured out, if you pass 'cfspreadsheet' as the third param to create object (bundle name) that forces Lucee to load it.
// Explicitly reference the bundle name
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook','cfspreadsheet');
It's worth noting the extension re-packages the POI jars inside a new bundle of it's own design, which is why the bundle name is cfspreadsheet
.