java.lang.NoClassDefFoundError:org/apache/poi/ss/usermodel/Row [英] java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Row
问题描述
我已经制作了一个小应用程序,可以从excel(xls文件)中读取并将内容显示到JTable中.在eclipse中一切正常,但是当我创建jar文件并尝试运行它时,出现以下问题:
java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Row
我发现奇怪的是,问题出在行上,当在行之前调用工作簿和工作表并且没有麻烦(至少从我所看到的情况).
我已经进行了很多研究,主要似乎是jar文件不在Class-Path中,但是打开jar和清单文件后,我可以看到所有jar.
Class-Path: poi-ooxml-4.0.1.jar poi-4.0.1.jar commons-codec-1.11.jar commons-collections4-4.2.jar commons-math3-3.6.1.jar commons-compress-1.18.jar curvesapi-1.05.jar poi-ooxml-schemas-4.0.1.jar xmlbeans-3.0.2.jar
这是我的pom.xml文件中的内容:
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>./</classpathPrefix>
<mainClass>com.clientdb.classes.DynamicRegForm</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
我还尝试下载jar文件并将其添加到项目中,而不是将依赖项添加到pom文件中,并且仍然是相同的错误. 有什么想法吗?
可能只有在运行jar时您会得到此信息,因为依赖项不可用/未打包在其中. >
尝试生成一个胖罐子" (也称为 uber-jar ),它将所有依赖项打包到罐子中:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>YOUR_JAR_FINAL_NAME</finalName>
</configuration>
</plugin>
</plugins>
</build>
与maven-shade-plugin
相关的文档可以在此处找到
更新:由于您使用的是可运行的jar文件,因此可以遵循 解决方案
Probably you are getting this only when you are running your jar because the dependencies are not available/packaged inside of it.
Try generating a "fat jar" (also known as uber-jar), it will package all your dependencies inside the jar:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>YOUR_JAR_FINAL_NAME</finalName>
</configuration>
</plugin>
</plugins>
</build>
Documentation related to the maven-shade-plugin
can be found in here
UPDATE: Since you are using a runnable jar file, you can follow this section of the documentation related to Executable Jars
这篇关于java.lang.NoClassDefFoundError:org/apache/poi/ss/usermodel/Row的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!