安装 cfspreadsheet 扩展后,Lucee 找不到 XSSFWorkbook
Lucee not finding XSSFWorkbook after cfspreadsheet extension installed
我在尝试创建 XSSFWorkbook
时收到错误消息
代码
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);
我也尝试了下面的行,但我收到了同样的错误。
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook');
错误
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];)
我已经为 Lucee 安装了 cfspreadsheet 扩展,并重新启动了 Lucee 和我的计算机,我已经验证 cfspreadsheet-3.0.1.jar
在 C:\lucee\tomcat\lucee-server\bundles
以及 lucee 附带的所有其他 jar 文件中可用。
如果我用 7-zip 打开 jar,我可以看到包含 poi-ooxml-3.15.jar
。在那个罐子里我可以浏览到 C:\lucee\tomcat\lucee-server\bundles\cfspreadsheet-3.0.1.jar\poi-ooxml-3.15.jar\org\apache\poi\xssf\usermodel\XSSFWorkbook.class
错误消息中的 lucee.core
让我觉得它无法识别我的扩展中的 jars,但我找不到启用它的设置。
我刚刚测试了您的代码,似乎在您至少实际点击 cfspreadsheet 标记一次之前,扩展中的 OSGI 包似乎并未真正加载。一旦我 运行 cfspreadsheet 标签,服务器管理中的 cfspreadsheet 包显示为 active 然后 createObject()
可以找到 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');
我也刚刚发现,如果您将 'cfspreadsheet' 作为第三个参数传递给创建对象(包名称),这会强制 Lucee 加载它。
// Explicitly reference the bundle name
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook','cfspreadsheet');
值得注意的是扩展 re-packages POI 罐子在它自己设计的新捆绑包中,这就是捆绑包名称为 cfspreadsheet
.
的原因
我在尝试创建 XSSFWorkbook
代码
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);
我也尝试了下面的行,但我收到了同样的错误。
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook');
错误
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];)
我已经为 Lucee 安装了 cfspreadsheet 扩展,并重新启动了 Lucee 和我的计算机,我已经验证 cfspreadsheet-3.0.1.jar
在 C:\lucee\tomcat\lucee-server\bundles
以及 lucee 附带的所有其他 jar 文件中可用。
如果我用 7-zip 打开 jar,我可以看到包含 poi-ooxml-3.15.jar
。在那个罐子里我可以浏览到 C:\lucee\tomcat\lucee-server\bundles\cfspreadsheet-3.0.1.jar\poi-ooxml-3.15.jar\org\apache\poi\xssf\usermodel\XSSFWorkbook.class
错误消息中的 lucee.core
让我觉得它无法识别我的扩展中的 jars,但我找不到启用它的设置。
我刚刚测试了您的代码,似乎在您至少实际点击 cfspreadsheet 标记一次之前,扩展中的 OSGI 包似乎并未真正加载。一旦我 运行 cfspreadsheet 标签,服务器管理中的 cfspreadsheet 包显示为 active 然后 createObject()
可以找到 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');
我也刚刚发现,如果您将 'cfspreadsheet' 作为第三个参数传递给创建对象(包名称),这会强制 Lucee 加载它。
// Explicitly reference the bundle name
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook','cfspreadsheet');
值得注意的是扩展 re-packages POI 罐子在它自己设计的新捆绑包中,这就是捆绑包名称为 cfspreadsheet
.