gpt4 book ai didi

java - 如何在 Java-Web Start 应用程序上读取 Excel 文件

转载 作者:太空宇宙 更新时间:2023-11-04 07:24:25 25 4
gpt4 key购买 nike

我正在开发一个 java-web-start 应用程序,它使用 java POI 读取 excel 文件。我的问题是每当我运行代码时它都会返回错误。

Exception in thread "Thread-13" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/WorkbookFactory
at digicare.tracking.serial.BulkUpload.UploadProgress$1read2.run(UploadProgress.java:89)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.WorkbookFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)

这是我的代码:

try {
InputStream inp = new FileInputStream(FilePath);
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
int maxrows = sheet.getPhysicalNumberOfRows();
for (int r = 1; r < maxrows; r++) {
Thread.sleep(1000);
lblCurrentRow.setText(String.valueOf(r));
prbProgBar.setValue(r);
txtOutPut.append(String.format("Done!!\n"));
}
} catch (Exception e) {
e.printStackTrace();
}

最佳答案

我以前遇到过这种情况,实际上不仅要添加一个jar文件,还有另一个文件,名为:poi-ooxml-x.jar(其中x是版本),是这个文件包含WorkbookFactory,而不是poi-x.jar,你必须包含它们

----------------------------------------------------------------------------

编辑我做了一些研究,我认为你的类路径问题与你的项目是一个 java web start 应用程序有关:

Can I rely on Class-Path in the Manifest file?

Java Web Start does not support the Class-Path entry in the manifest file. The Class-Path attribute is entirely file-centric, where as Java Web Start and JNLP is Web-centric, i.e., based on URLs. Thus, the two models do not merge easily.

Instead of relying on the Class-Path entry, you can list multiple JAR files in the JNLP file, e.g.,:

<resources>
<jar href="A.jar"/>
<jar href="B.jar"/>
</resources>

这是我找到它的链接:http://webstartfaq.com/#52

关于java - 如何在 Java-Web Start 应用程序上读取 Excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18784874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com