gpt4 book ai didi

Java - NoClassDefFoundError XSSFWorkbook

转载 作者:行者123 更新时间:2023-11-29 04:08:59 30 4
gpt4 key购买 nike

我创建 CSV 到 XLSX 应用程序 - My first question

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/xssf/usermodel/XSSFWorkbook
at com.test.csv2xlsx.Csv2Xlsx.<init>(Csv2Xlsx.java:35)
at com.test.csv2xlsx.Csv2Xlsx.main(Csv2Xlsx.java:49)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.xssf.usermodel.XSSFWorkbook
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more

我阅读了所有关于这个错误的文章,但我已经有了所有的依赖

<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.3</version>
</dependency>
</dependencies>

现在我不确定是哪里出了问题

enter image description here

最佳答案

这是一个很常见的问题。您的项目的依赖项未包含在您执行的 jar 中,导致 NoClassDefFoundError

要解决此问题,请将其添加到 pom.xmlplugins 部分:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
com.mypackage.Main
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>

然后执行 mvn clean package,当在目标目录中完成后,您将找到一个可执行文件 jar_name-jar-with-dependencies.jar,其中包含所有必需的依赖项。

最后简单地运行 java -jar jar_name-jar-with-dependencies.jar

关于Java - NoClassDefFoundError XSSFWorkbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56288387/

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