Jar文件给出了java.lang.NoClassDefFoundError [英] Jar file gives java.lang.NoClassDefFoundError

查看:466
本文介绍了Jar文件给出了java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Eclipse项目运行正常,当我在Eclipse中运行它。我在Eclipse中创建了一个Jar文件。但是当我使用以下命令运行它时:

  D:\Java\projects\fetch> java -Xss1000m  - XX:-UseGCOverheadLimit -Xmx5048m -jar bin\fetch.jar 

我收到以下错误: / p>

 线程main中的异常java.lang.NoClassDefFoundError:info / monitorenter / cpdetector / io / ICodepageDetector 
在java 。java.lang.Class.privateGetDeclaredMethods .Class.getMethod(未知源)
at sun.launcher.LauncherHelper.getMainMethod(未知来源)
at sun.launcher.LauncherHelper.checkAndLoadMain(未知来源)
导致:java.lang .ClassNotFoundException:info.monitorenter.cpdetector.io.ICodepageDetector
在java.net.URLClassLoader $ 1.run(未知来源)
在java.net.URLClassLoader $ 1.run(未知来源)
在ja va.security.AccessController.doPrivileged(Native Method)
在java.net.URLClassLoader.findClass(未知源)
在java.lang.ClassLoader.loadClass(未知来源)
at sun。 misc.Launcher $ AppClassLoader.loadClass(未知来源)
在java.lang.ClassLoader.loadClass(未知来源)
... 6更多

该jar的内容是:

  com(folder) 
dist(文件夹)
doc(文件夹)
lib(文件夹,包含所有jar,包括cpdetector jar)
META-INF(文件夹)
resources文件夹)
源(文件夹)
.classpath(文件)
.project(文件)
hibernate.cfg.xml(文件)
log4j.xml(文件)

.classpath文件的内容是:

 <?xml version =1.0encoding =UTF-8?> 
< classpath>
< classpathentry kind =srcpath =src/>
< classpathentry kind =libpath =D:/Java/projects/boilerpipe-master/target/boilerpipe-core-1.2.2.jar/>
< classpathentry kind =libpath =D:/Java/projects/boilerpipe-master/target/boilerpipe-core-1.2.2-jar-with-dependencies.jar/>
< classpathentry kind =libpath =lib / jsoup-1.7.2.jar/>
< classpathentry kind =libpath =lib / ahocorasick-1.4-SNAPSHOT-all.jar/>
< classpathentry kind =libpath =lib / ahocorasick-1.4-SNAPSHOT.jar/>
< classpathentry kind =libpath =lib / antlr-3.4-complete.jar/>
< classpathentry kind =libpath =lib / chardet.jar/>
< classpathentry kind =libpath =lib / commons-fileupload-1.2.2.jar/>
< classpathentry kind =libpath =lib / commons-httpclient-3.1.jar/>
< classpathentry kind =libpath =lib / commons-io-2.4.jar/>
< classpathentry kind =libpath =lib / commons-lang-2.6.jar/>
< classpathentry kind =libpath =lib / commons-lang3-3.1.jar/>
< classpathentry kind =libpath =lib / commons-validator-1.4.0.jar/>
< classpathentry kind =libpath =lib / horrorss-2.2.0.jar/>
< classpathentry kind =libpath =lib / jackson-core-2.1.4.jar/>
< classpathentry kind =libpath =lib / jackson-core-asl-1.9.12.jar/>
< classpathentry kind =libpath =lib / jackson-mapper-asl-1.9.12.jar/>
< classpathentry kind =libpath =lib / jdom-1.1.3.jar/>
< classpathentry kind =libpath =lib / jdom-2.0.4.jar/>
< classpathentry kind =libpath =lib / jericho-html-3.3.jar/>
< classpathentry kind =libpath =lib / jline.jar/>
< classpathentry kind =libpath =lib / joda-time-2.2.jar/>
< classpathentry kind =libpath =lib / lucene-analyzeers-3.6.2.jar/>
< classpathentry kind =libpath =lib / lucene-core-3.6.2.jar/>
< classpathentry kind =libpath =lib / nekohtml-1.9.13.jar/>
< classpathentry kind =libpath =lib / rome-1.0.jar/>
< classpathentry kind =libpath =lib / tika-app-1.3.jar/>
< classpathentry kind =libpath =lib / xerces-2.9.1.jar/>
< classpathentry kind =libpath =lib / xstream-1.4.4.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / envers / hibernate-envers-4.2.0.Final.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / jpa / hibernate-entitymanager-4.2.0.Final.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / required / antlr-2.7.7.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / required / dom4j-1.6.1.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / required / hibernate-commons-annotations-4.0.1.Final.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / required / hibernate-core-4.2.0.Final.jarsourcepath =C:/ Users / Nick /.m2/repository/org/hibernate/hibernate-core/4.2.0.Final/hibernate-core-4.2.0.Final-sources.jar\"/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / required / hibernate-jpa-2.0-api-1.0.1.Final.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / required / javassist-3.15.0-GA.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / required / jboss-logging-3.1.0.GA.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / required / jboss-transaction-api_1.1_spec-1.0.0.Final.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / optional / ehcache / ehcache-core-2.4.3.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / optional / ehcache / hibernate-ehcache-4.2.0.Final.jar/>
< classpathentry kind =libpath =lib / hibernate-release-4.2.0.Final / optional / ehcache / slf4j-api-1.6.1.jar/>
< classpathentry kind =libpath =C:/ java / tomcat6 / tomcat 6.0.35 / lib / mysql-connector-java-5.1.22-bin.jar/>
< classpathentry kind =libpath =lib / htmlcleaner-2.4.jar/>
< classpathentry kind =libpath =lib / freebase-java-1.0.0.jar/>
< classpathentry kind =libpath =lib / javax.mail.jar/>
< classpathentry kind =libpath =lib / opencsv-2.3.jar/>
< classpathentry kind =libpath =lib / google-api-client-1.14.1-beta.jar/>
< classpathentry kind =libpath =lib / google-http-client-1.14.1-beta.jar/>
< classpathentry kind =libpath =lib / json-simple-1.1.1.jar/>
< classpathentry kind =libpath =lib / json-smart-1.1.jar/>
< classpathentry kind =libpath =lib / javatuples-1.2.jar/>
< classpathentry kind =libpath =lib / json-path-0.8.1.jarsourcepath =C:/Users/Nick/.m2/repository/com/jayway/jsonpath/json-路径/ 0.8.1 / JSON-路径0.8.1-sources.jar/>
< classpathentry kind =libpath =lib / json-20090211.jar/>
< classpathentry kind =libpath =lib / lucene-4.3.0 / core / lucene-core-4.3.0.jar/>
< classpathentry kind =libpath =lib / lucene-4.3.0 / suggest / lucene-suggest-4.3.0.jar/>
< classpathentry kind =libpath =lib / solr-core-4.2.1.jar/>
< classpathentry kind =libpath =lib / solr-solrj-4.2.1.jar/>
< classpathentry kind =libpath =lib / quartz-all-2.1.7.jar/>
< classpathentry kind =libpath =lib / simplelatlng-1.2.0.jar/>
< classpathentry kind =libpath =lib / obsidian.jar/>
< classpathentry kind =libpath =lib / CareerjetAPIClient.jar/>
< classpathentry kind =conpath =org.eclipse.jdt.launching.JRE_CONTAINER / org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType / jre6/>
< classpathentry kind =libpath =lib / goose-2.1.22-jar-with-dependencies.jar/>
< classpathentry kind =conpath =com.ateji.bldt.ui.ATEJILIB_CONTAINER/>
< classpathentry kind =libpath =lib / commons-lang-2.4.jar/>
< classpathentry kind =libpath =lib / commons-logging-1.0.4.jar/>
< classpathentry kind =libpath =lib / httpclient-4.2.3.jar/>
< classpathentry kind =libpath =lib / httpcore-4.2.2.jar/>
< classpathentry kind =libpath =lib / httpmime-4.2.3.jar/>
< classpathentry kind =libpath =lib / commons-codec-1.2.jar/>
< classpathentry kind =libpath =lib / commons-math3-3.2.jarsourcepath =sources/>
< classpathentry kind =libpath =lib / guava-14.0.1.jar/>
< classpathentry kind =libpath =lib / cpdetector_1.0.10.jar/>
< classpathentry kind =outputpath =bin/>
< / classpath>

我已经google了java.lang.NoClassDefFoundError,已经尝试了很多东西,但没有他们工作。欢迎所有的建议。谢谢。

解决方案

当您在命令行中运行java时,您必须提供类路径。

  java -cp lib / commons-fileupload-1.2.2.jar; ... 
/ pre>

或者您在eclipse(启动配置)中运行它,eclipse为您提供了类路径。 .classpath文件是一个eclipse工件,因此只能被eclipse识别。



或者你可以使用 eclipse的runnable jar导出导出 - > Runnable Jar文件。确保在导出对话框的库处理部分中选择将所需的库提取到生成的JAR。


I have an Eclipse project that runs fine when I run it in Eclipse. I have created a Jar file in Eclipse. But when I run it using the following command:

D:\Java\projects\fetch>java -Xss1000m -XX:-UseGCOverheadLimit -Xmx5048m -jar bin\fetch.jar

I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: info/monitorenter/cpdetector/io/ICodepageDetector
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: info.monitorenter.cpdetector.io.ICodepageDetector
    at java.net.URLClassLoader$1.run(Unknown Source)
    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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 6 more

The contents of the jar are:

com (folder)
dist (folder)
doc (folder)
lib  (folder, contains all the jars, including the cpdetector jar)
META-INF (folder)
resources (folder)
sources (folder)
.classpath (file)
.project (file)
hibernate.cfg.xml (file)
log4j.xml (file)

The contents of the .classpath file are:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="D:/Java/projects/boilerpipe-master/target/boilerpipe-core-1.2.2.jar"/>
<classpathentry kind="lib" path="D:/Java/projects/boilerpipe-master/target/boilerpipe-core-1.2.2-jar-with-dependencies.jar"/>
<classpathentry kind="lib" path="lib/jsoup-1.7.2.jar"/>
<classpathentry kind="lib" path="lib/ahocorasick-1.4-SNAPSHOT-all.jar"/>
<classpathentry kind="lib" path="lib/ahocorasick-1.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/antlr-3.4-complete.jar"/>
<classpathentry kind="lib" path="lib/chardet.jar"/>
<classpathentry kind="lib" path="lib/commons-fileupload-1.2.2.jar"/>
<classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="lib/commons-io-2.4.jar"/>
<classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.1.jar"/>
<classpathentry kind="lib" path="lib/commons-validator-1.4.0.jar"/>
<classpathentry kind="lib" path="lib/horrorss-2.2.0.jar"/>
<classpathentry kind="lib" path="lib/jackson-core-2.1.4.jar"/>
<classpathentry kind="lib" path="lib/jackson-core-asl-1.9.12.jar"/>
<classpathentry kind="lib" path="lib/jackson-mapper-asl-1.9.12.jar"/>
<classpathentry kind="lib" path="lib/jdom-1.1.3.jar"/>
<classpathentry kind="lib" path="lib/jdom-2.0.4.jar"/>
<classpathentry kind="lib" path="lib/jericho-html-3.3.jar"/>
<classpathentry kind="lib" path="lib/jline.jar"/>
<classpathentry kind="lib" path="lib/joda-time-2.2.jar"/>
<classpathentry kind="lib" path="lib/lucene-analyzers-3.6.2.jar"/>
<classpathentry kind="lib" path="lib/lucene-core-3.6.2.jar"/>
<classpathentry kind="lib" path="lib/nekohtml-1.9.13.jar"/>
<classpathentry kind="lib" path="lib/rome-1.0.jar"/>
<classpathentry kind="lib" path="lib/tika-app-1.3.jar"/>
<classpathentry kind="lib" path="lib/xerces-2.9.1.jar"/>
<classpathentry kind="lib" path="lib/xstream-1.4.4.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/envers/hibernate-envers-4.2.0.Final.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/jpa/hibernate-entitymanager-4.2.0.Final.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/required/antlr-2.7.7.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/required/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/required/hibernate-commons-annotations-4.0.1.Final.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/required/hibernate-core-4.2.0.Final.jar" sourcepath="C:/Users/Nick/.m2/repository/org/hibernate/hibernate-core/4.2.0.Final/hibernate-core-4.2.0.Final-sources.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/required/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/required/javassist-3.15.0-GA.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/required/jboss-logging-3.1.0.GA.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/required/jboss-transaction-api_1.1_spec-1.0.0.Final.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/optional/ehcache/ehcache-core-2.4.3.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/optional/ehcache/hibernate-ehcache-4.2.0.Final.jar"/>
<classpathentry kind="lib" path="lib/hibernate-release-4.2.0.Final/optional/ehcache/slf4j-api-1.6.1.jar"/>
<classpathentry kind="lib" path="C:/java/tomcat6/tomcat 6.0.35/lib/mysql-connector-java-5.1.22-bin.jar"/>
<classpathentry kind="lib" path="lib/htmlcleaner-2.4.jar"/>
<classpathentry kind="lib" path="lib/freebase-java-1.0.0.jar"/>
<classpathentry kind="lib" path="lib/javax.mail.jar"/>
<classpathentry kind="lib" path="lib/opencsv-2.3.jar"/>
<classpathentry kind="lib" path="lib/google-api-client-1.14.1-beta.jar"/>
<classpathentry kind="lib" path="lib/google-http-client-1.14.1-beta.jar"/>
<classpathentry kind="lib" path="lib/json-simple-1.1.1.jar"/>
<classpathentry kind="lib" path="lib/json-smart-1.1.jar"/>
<classpathentry kind="lib" path="lib/javatuples-1.2.jar"/>
<classpathentry kind="lib" path="lib/json-path-0.8.1.jar" sourcepath="C:/Users/Nick/.m2/repository/com/jayway/jsonpath/json-path/0.8.1/json-path-0.8.1-sources.jar"/>
<classpathentry kind="lib" path="lib/json-20090211.jar"/>
<classpathentry kind="lib" path="lib/lucene-4.3.0/core/lucene-core-4.3.0.jar"/>
<classpathentry kind="lib" path="lib/lucene-4.3.0/suggest/lucene-suggest-4.3.0.jar"/>
<classpathentry kind="lib" path="lib/solr-core-4.2.1.jar"/>
<classpathentry kind="lib" path="lib/solr-solrj-4.2.1.jar"/>
<classpathentry kind="lib" path="lib/quartz-all-2.1.7.jar"/>
<classpathentry kind="lib" path="lib/simplelatlng-1.2.0.jar"/>
<classpathentry kind="lib" path="lib/obsidian.jar"/>
<classpathentry kind="lib" path="lib/CareerjetAPIClient.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre6"/>
<classpathentry kind="lib" path="lib/goose-2.1.22-jar-with-dependencies.jar"/>
<classpathentry kind="con" path="com.ateji.bldt.ui.ATEJILIB_CONTAINER"/>
<classpathentry kind="lib" path="lib/commons-lang-2.4.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"/>
<classpathentry kind="lib" path="lib/httpclient-4.2.3.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.2.2.jar"/>
<classpathentry kind="lib" path="lib/httpmime-4.2.3.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.2.jar"/>
<classpathentry kind="lib" path="lib/commons-math3-3.2.jar" sourcepath="sources"/>
<classpathentry kind="lib" path="lib/guava-14.0.1.jar"/>
<classpathentry kind="lib" path="lib/cpdetector_1.0.10.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

I have already googled java.lang.NoClassDefFoundError , and have already tried a lot of stuff but none of them work. All suggestions are welcome. Thank you.

解决方案

You have to provide the classpath when you run java on the command line.

java -cp lib/commons-fileupload-1.2.2.jar;......

or you run it within eclipse (Launch Configuration) and eclipse provides the classpath for you. The .classpath file is an eclipse artifact and thus only recognized by eclipse.

Or you can use eclipse's runnable jar export. Export -> Runnable Jar File. Ensure that you selected "Extract required libraries into generated JAR" in the Library handling section of the export dialog.

这篇关于Jar文件给出了java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆