java org/apache/poi/ss/usermodel/Sheet 的 NoClassDefFoundError Jar 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17581232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NoClassDefFoundError Jar Error for org/apache/poi/ss/usermodel/Sheet
提问by Taztingo
I have seen this question asked a lot, but I still can't figure out a solution to it. Well a solution that works for me. I have a project that is using Apache POI, and I made sure to include all the external JARs. The project compiles and runs fine in eclipse but when I run the jar with "java -jar Test.jar
" I get this error:
我看到这个问题问了很多,但我仍然想不出解决办法。一个对我有用的解决方案。我有一个使用 Apache POI 的项目,我确保包含所有外部 JAR。该项目在 Eclipse 中编译并运行良好,但是当我使用“ java -jar Test.jar
”运行 jar 时,出现此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Sheet
线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Sheet
I'm not sure if this is useful information, but I created a lib folder for my project and put the poi library in there. This means that the dependcies are in the JAR file when I create it, I figured I should mention this because I saw a few solutions about just having your external jars right next to your executable jar. I also tried setting my classpath to the directory of the project.
我不确定这是否是有用的信息,但我为我的项目创建了一个 lib 文件夹并将 poi 库放在那里。这意味着当我创建它时依赖项在 JAR 文件中,我想我应该提到这一点,因为我看到了一些关于将外部 jar 放在可执行 jar 旁边的解决方案。我还尝试将我的类路径设置为项目目录。
What do I seem to be doing wrong?
我似乎做错了什么?
回答by Reimeus
The Apache POI JAR fileis not on your runtime classpath. Rebuild Test.jar
with the following manifest entry in the MANIFEST.MF
file
在Apache的POI JAR文件是不是在运行时类路径。Test.jar
使用MANIFEST.MF
文件中的以下清单条目重建
Class-Path: poi-3.9-20121203.jar
回答by CodeBlind
When the java -jar [filename].jar
command fails, it's almost always because of one of two things:
当java -jar [filename].jar
命令失败时,几乎总是因为以下两件事之一:
Your MANIFEST.MF is messed up and doesn't list dependencies properly. Make sure all jar dependencies in your manifest file point to jars, relative to your jar's parent directory.
You are missing .class files, either in your specific jar or in one you depend on. Ensure your jar contains
org/apache/poi/ss/usermodel/Sheet.class
or that your manifest hierarchy points to a jar that contains that class.
您的 MANIFEST.MF 搞砸了,没有正确列出依赖项。确保清单文件中的所有 jar 依赖项都指向 jar,相对于 jar 的父目录。
您缺少 .class 文件,无论是在您的特定 jar 中还是在您依赖的 jar 中。确保您的 jar 包含
org/apache/poi/ss/usermodel/Sheet.class
或您的清单层次结构指向包含该类的 jar。
回答by anubhava
You will need to provide classpath in Jar file's manifest file. See this official doc
您需要在 Jar 文件的清单文件中提供类路径。看这个官方文档
An Example
一个例子
We want to load classes in MyUtils.jar into the class path for use in MyJar.jar. These two JAR files are in the same directory.
我们想将 MyUtils.jar 中的类加载到类路径中以在 MyJar.jar 中使用。这两个 JAR 文件位于同一目录中。
We first create a text file named Manifest.txt
with the following contents:
我们首先创建一个以Manifest.txt
以下内容命名的文本文件:
Class-Path: MyUtils.jar
回答by Diego Pino
First check if your target jar (Test.jar
) is a fat jar containing all the required dependencies.
首先检查您的目标 jar ( Test.jar
) 是否是包含所有必需依赖项的胖 jar。
$ jar tf Test.jar
You should see your lib/
folder there containing all the required dependencies (including Apache POI). If that's the case do what others suggested, add Apache POI to your MANIFEST.MF
.
您应该在lib/
那里看到包含所有必需依赖项(包括 Apache POI)的文件夹。如果是这种情况,请按照其他人的建议进行操作,将 Apache POI 添加到您的MANIFEST.MF
.
About having your jar dependencies in a separate folder, as you suggested, that's also possible. Imagine your dependencies where stored in a lib/
folder outside your Test.jar
. You could run your code with this command:
关于将 jar 依赖项放在单独的文件夹中,正如您所建议的,这也是可能的。想象一下,你的依赖,其中一个存储在lib/
文件夹之外Test.jar
。您可以使用以下命令运行您的代码:
$ java -cp ".:lib/*" org.Test.Main
It simply adds all the .jars within lib/ folder to your classpath. In this case you also need to specify the name of the main class (full name).
它只是将 lib/ 文件夹中的所有 .jar 文件添加到您的类路径中。在这种情况下,您还需要指定主类的名称(全名)。
回答by Myk Agustin
I also got this problem and tried to google it..
我也遇到了这个问题并试图用谷歌搜索它..
i have found out that i have to read the error log
我发现我必须阅读错误日志
I cant save my file to .xls so in my case after reading the error i found that a jar file is missing i just added the jar file poi-3.7-20101029 located in the ext folder of my ireport
我无法将我的文件保存到 .xls 所以在我的情况下,在阅读错误后,我发现缺少一个 jar 文件,我刚刚添加了位于 ireport 的 ext 文件夹中的 jar 文件 poi-3.7-20101029
ex.YourIReportFolder/ireport/modules/ext-poi.x.x-xxxx
ex.YourIReportFolder/ireport/modules/ext-poi.xx-xxxx
hope this helps :)
希望这可以帮助 :)