gpt4 book ai didi

java.lang.NoClassDefFoundError,但是所有的jar文件都在

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:39 26 4
gpt4 key购买 nike

解决了,我让它工作了

我刚刚完成了我的第一个真正的 JAVA 程序。它是一个允许您打开 .xlsx 文件的程序,该程序从该文件中提取数据并将其显示在文本区域中。

在 Eclipse 中,程序运行良好,但导出的 jar 却不行。导出项目后,我在 CMD 中使用 java -jar c://...... 打开它,它打开得很好。但是,当我尝试打开 excel 文件时出现此错误:

Error message

所以基本上所需的 .jar 文件之一似乎在运行时不可用。但是我相信所有需要的 poi-3.9 和 xmlbeans 都可用。看这个:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="src/xmlbeans-2.3.0.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-examples-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-excelant-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-ooxml-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-ooxml-schemas-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/poi-scratchpad-3.9-20121203.jar"/>
<classpathentry exported="true" kind="lib" path="src/log4j-1.2.13.jar"/>
<classpathentry exported="true" kind="lib" path="src/junit-3.8.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/commons-logging-1.1.jar"/>
<classpathentry exported="true" kind="lib" path="commons-collections4-4.1-javadoc.jar"/>
<classpathentry exported="true" kind="lib" path="commons-collections4-4.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/commons-codec-1.5.jar"/>
<classpathentry exported="true" kind="lib" path="poi-ooxml-3.9.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="lib/commons-codec-1.10.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-io-2.5.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-lang3-3.4.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/cssparser-0.9.20.jar"/>
<classpathentry exported="true" kind="lib" path="lib/htmlunit-2.23.jar"/>
<classpathentry exported="true" kind="lib" path="lib/htmlunit-core-js-2.23.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpclient-4.5.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpcore-4.4.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpmime-4.5.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jetty-io-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jetty-util-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/neko-htmlunit-2.23.jar"/>
<classpathentry exported="true" kind="lib" path="lib/sac-1.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/serializer-2.7.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/websocket-api-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/websocket-client-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/websocket-common-9.2.18.v20160721.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xalan-2.7.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xercesImpl-2.11.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xml-apis-1.4.01.jar"/>
<classpathentry exported="true" kind="lib" path="src/jsoup-1.10.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/dom4j-1.6.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/selenium-server-standalone-3.0.1.jar"/>
<classpathentry exported="true" kind="lib" path="src/stax-api-1.0.1.jar"/>
<classpathentry kind="lib" path="src/poi-ooxml-3.11.jar"/>
<classpathentry exported="true" kind="lib" path="src/xbean-2.0.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

另请参阅构建路径配置中我的订单和导出选项卡。

Export

我错过了什么吗?非常感谢任何帮助!

编辑:我做了一些更改,所有必需的 jar 都在我项目的 lib/文件夹中。如果我导出 jar 并查看 jar 内容:jar tf“location.jar”。我得到以下信息。所以我相信这意味着一切都很好地导出了。关于可能出现问题的任何建议,因为我一直遇到同样的错误。

Contents of JAR and Classpath

最佳答案

这是因为 eclipse 读取您的类路径依赖项并将它们包含在运行时中,但用于通过 java -jar 运行导出的 jar。命令,您必须添加 -cp <your-jar-locations-semicolon-separated>这样 jvm 就知道 jars 在执行时要包含在类路径中。

或者,考虑构建一个阴影 jar,其中包含导出的 jar 中的所有依赖 jar。

关于java.lang.NoClassDefFoundError,但是所有的jar文件都在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41611739/

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