java.lang.NoClassDefFoundError,但所有jar文件都已就绪

时间:2017-01-12 11:12:49

标签: java noclassdeffounderror xssf

已经解决,我开始工作了

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

在eclipse中,该程序完全正常,但导出的jar并不是。导出项目后,我使用java -jar c:// ......在CMD中打开它,它打开就好了。但是,当我尝试打开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>

另请参阅构建路径配置中的Order和Exporttab。

Export

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

编辑: 我做了一些更改,所有必要的jar都在我项目的lib /文件夹中。如果我导出jar并使用:jar tf&#34; location.jar&#34;查看jar内容。我得到以下内容。所以我相信这意味着一切都很好地输出。关于可能出错的任何建议,因为我不断得到同样的错误。

Contents of JAR and Classpath

1 个答案:

答案 0 :(得分:2)

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

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