Lucee安装cfspreadsheet扩展后无法找到XSSFWorkbook。

huangapple go评论72阅读模式
英文:

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');

错误信息

无法通过类的字符串名称加载类因为找不到指定名称 [org.apache.poi.xssf.usermodel.XSSFWorkbook] 的类定义
由于 java.lang.ClassNotFoundException:org.apache.poi.xssf.usermodel.XSSFWorkbook;
java.lang.ClassNotFoundException:org.apache.poi.xssf.usermodel.XSSFWorkbook 未在 lucee.core [46] 中找到;)

我已经安装了适用于 Lucee 的 cfspreadsheet 扩展并重新启动了 Lucee 和我的计算机我已经确认 `cfspreadsheet-3.0.1.jar` 与 Lucee 一起提供在 `C:\lucee\tomcat\lucee-server\bundles`以及 Lucee 提供的所有其他 jar 文件

如果我使用 7-zip 打开这个 jar 文件我可以看到其中包括了 `poi-ooxml-3.15.jar`。在该 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` 让我认为它无法识别扩展中的 jar 文件但是我找不到启用此功能的设置


<details>
<summary>英文:</summary>

I&#39;m receiving an error when trying to create an `XSSFWorkbook`

Code 

    currentCharterTemplate = &#39;UnusedTicketsWorkbook.xlsx&#39;;
	currentFilePath = getDirectoryFromPath(getCurrentTemplatePath());
	javaFile = createObject(&#39;java&#39;, &#39;java.io.File&#39;).init(currentFilePath &amp; currentCharterTemplate);
	excelFile = createObject(&#39;java&#39;, &#39;java.io.FileInputStream&#39;).init(javaFile);
	xssfWorkbook = createObject(&#39;java&#39;, &#39;org.apache.poi.xssf.usermodel.XSSFWorkbook&#39;);
	xssfWorkbook = createObject(&#39;java&#39;, &#39;org.apache.poi.xssf.usermodel.XSSFWorkbook&#39;).init(excelFile);

I also tried just the line below and I receive the same error.

    xssfWorkbook = createObject(&#39;java&#39;, &#39;org.apache.poi.xssf.usermodel.XSSFWorkbook&#39;);

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&#39;ve installed the cfspreadsheet extension for Lucee, and restarted Lucee and my computer, I&#39;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&#39;s not recognizing jars from my extensions, but I can&#39;t find a setting to enable this.

</details>


# 答案1
**得分**: 2

```js
// 强制 Lucee 激活 bundle
spreadsheet action="read" src="#expandPath( 'UnusedTicketsWorkbook.xlsx' )#" name="test";

xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook');

我还发现,如果你将 'cfspreadsheet' 作为 createObject 的第三个参数(bundle 名称)传递,这会强制 Lucee 加载它。

// 明确引用 bundle 名称
xssfWorkbook = createObject('java', 'org.apache.poi.xssf.usermodel.XSSFWorkbook','cfspreadsheet');

值得注意的是,该扩展将 POI jars 重新打包到自己设计的新 bundle 中,这就是为什么 bundle 名称是 'cfspreadsheet'。


<details>
<summary>英文:</summary>
I just tested your code and it seems that the OSGI bundle from the extension isn&#39;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.
```js
// Force Lucee to activate the bundle
spreadsheet action=&quot;read&quot; src=&quot;#expandPath( &#39;UnusedTicketsWorkbook.xlsx&#39; )#&quot; name=&quot;test&quot;;
xssfWorkbook = createObject(&#39;java&#39;, &#39;org.apache.poi.xssf.usermodel.XSSFWorkbook&#39;);

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(&#39;java&#39;, &#39;org.apache.poi.xssf.usermodel.XSSFWorkbook&#39;,&#39;cfspreadsheet&#39;);

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.

huangapple
  • 本文由 发表于 2020年9月11日 10:44:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63840125.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定