[英]Apache POI Java program working fine in IDE (Eclipse) but encounter NoClassDefFoundError when I tried to run it as a runnable jar
I got a very strange problem that my program runs in Eclipse but doesn't run well wen exported as a runnable jar. 我遇到了一个非常奇怪的问题,我的程序在Eclipse中运行,但是在作为可运行jar导出时运行得不好。 I am getting ClassNotFoundException
. 我正在收到ClassNotFoundException
。
C:\Users\43156557\workspace\CAF3_IDE\MFTRelease>java -jar MSDocWriter.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:149)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:136)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:81)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:220)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:1
11)
at com.hsbc.glt.automation.test.mft.util.MSDocumentWriter.initializeDocu
ment(MSDocumentWriter.java:92)
at com.hsbc.glt.automation.test.mft.util.MSDocumentWriter.main(MSDocumen
tWriter.java:70)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 14 more
C:\Users\43156557\workspace\CAF3_IDE\MFTRelease>
ClassNotFoundException usually depicts that JVM is not able to load the required class file from the defined classpath (either the path is not correct or the class / jar is not present at the path). ClassNotFoundException通常表示JVM无法从已定义的类路径中加载所需的类文件(该路径不正确或该路径中不存在类/ jar)。
The Error in current scenario might be cause have missed to include the Dependency libraries when creating the jar file. 当前情况下的错误可能是由于在创建jar文件时错过了包含依赖项库的原因。 Since on eclipse you have the class-path correctly including those its working perfectly. 由于在eclipse上,您具有正确的类路径,包括其工作正常的那些。
Make sure that you check "Package Required Jar into generated JAR" , this will include the jar files automatically from your eclipse build path. 确保选中“将所需的Jar打包到生成的JAR中”,这将自动从eclipse构建路径中包含jar文件。
for detailed info this might come handy Include Dependent Jars in Executable Jar 有关详细信息,这可能会派上用场在可执行Jar中包括依赖罐
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.