gpt4 book ai didi

java - Apache POI Classnotfound 异常 org.apache.poi.ss.usermodel.Cell

转载 作者:行者123 更新时间:2023-12-02 01:58:06 25 4
gpt4 key购买 nike

您好,我在运行 jar 时遇到以下异常。有人可以帮忙吗?

U2007750s-MacBook-Pro:target u2007750$ java -jar ExcelCSVConverter-0.0.1-SNAPSHOT.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Cell
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Cell
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

更新:

到目前为止,我在 pom.xml 中只有 poi-ooxml 依赖项:

     <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>

程序在eclipse中正确执行。仅在命令行中发生错误。

现在经过你们的推荐,我还添加了第二个依赖项poi:

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>

但仍然没有成功。现在这个类出现错误:

U2007750s-MacBook-Pro:target u2007750$ java -jar ExcelCSVConverter-0.0.1-SNAPSHOT.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/impl/values/XmlValueOutOfRangeException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

方法是:

private static String getCellData(XSSFCell myCell) {
String cellData = "";
if (myCell == null) {
cellData += CSV_SEPERATOR_CHAR;
} else {
try {
switch (myCell.getCellTypeEnum()) {
case STRING:
case BOOLEAN:
cellData += myCell.getRichStringCellValue() + CSV_SEPERATOR_CHAR;
break;
case NUMERIC:
cellData += getNumericValue(myCell);
break;
case FORMULA:
cellData += getFormulaValue(myCell);
default:
cellData += CSV_SEPERATOR_CHAR;
}
} catch (XmlValueOutOfRangeException e) {
int a =2;
//System.out.println("XmlValueOutOfRangeException for: "+ myCell.getRawValue());
String rawValue = myCell.getRawValue();
while(rawValue.startsWith("0")) {
rawValue = rawValue.substring(1);
}
cellData += rawValue+ CSV_SEPERATOR_CHAR;
}
}
return cellData;
}

最佳答案

您需要下载以下 JAR 文件并将它们添加到您的构建路径中。

Apache POI
Apache POI-OOXML

如果您使用 Maven:

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.0.1</version>
</dependency>


如果您使用 Gradle:

// https://mvnrepository.com/artifact/org.apache.poi/poi
compile group: 'org.apache.poi', name: 'poi', version: '3.17'
// https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'

关于java - Apache POI Classnotfound 异常 org.apache.poi.ss.usermodel.Cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52038713/

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