简体   繁体   English

Apache POI Java程序在IDE(Eclipse)中运行良好,但是当我尝试将其作为可运行的jar运行时遇到NoClassDefFoundError

[英]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.

相关问题 具有Apache POI的可运行jar - Runnable jar with Apache POI Eclipse Java-程序可以在Eclipse中运行,但不能作为可运行的jar - Eclipse Java - Program works in eclipse but not as runnable jar noclassdeffounderror 在一个简单的网络程序中。 我正在使用 Eclipse IDE 运行 java 程序 - noclassdeffounderror in a simple networking program. I am using Eclipse IDE to run java programs Apache POI 在导出可运行 Jar 时极其缓慢 - Apache POI extremely slow when exporting Runnable Jar with Package option in Eclipse Java项目在Eclipse上工作但在导出到runnable jar文件时不起作用 - Java project working on Eclipse but not working when exported to runnable jar file 可运行的jar时出现NoClassDefFoundError - NoClassDefFoundError when runnable jar 当我在Apache POI库中使用Calibri字体时,在可运行jar中的列宽度未正确显示 - Column width not coming properly in runnable jar when I use Calibri font in apache poi library 为什么当我将国际象棋项目作为一个可运行的jar文件运行时,我得到一个奇怪的行为,而当我在eclipse中运行它时一切正常? - Why when I run my chess project as a runnable jar file I get a strange behavior while when I run it inside eclipse everything works just fine? java NoClassDefFoundError:com / google / api / client / extensions / java6 / auth / oauth2 / VerificationCodeReceiver当我运行jar而不是IDE时 - java NoClassDefFoundError: com/google/api/client/extensions/java6/auth/oauth2/VerificationCodeReceiver when I run jar but not on IDE 在Eclipse中播放视频效果很好,但是当将Java项目导出为可运行的JAR文件时,它不再起作用 - Playing videos works fine in Eclipse but when exporting the java project as an runnable JAR file it doesnt work anymore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM