Exception in thread “main” java.lang.NoClassDefFoundError:

旧城冷巷雨未停 提交于 2020-01-15 10:43:15

问题


I am trying to run a java program and I am getting the following run time error.The error is shown below.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/params/SyncBasicHttpParams
    at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:157)
    at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448)
    at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:309)
    at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:466)
    at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:286)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
    at net.floodlightcontroller.core.internal.PacketStreamerClient.registerForPackets(PacketStreamerClient.java:90)
    at net.floodlightcontroller.core.internal.PacketStreamerClient.main(PacketStreamerClient.java:51)
Caused by: java.lang.ClassNotFoundException: org.apache.http.params.SyncBasicHttpParams
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 10 more

The error is java.lang.NoClassDefFoundError

Now the Obvious reason of NoClassDefFoundError is that a particular class is not available in Classpath, so we need to add that into Classpath or we need to check why it’s not available in Classpath if we are expecting it to be.

Now the files that I have added to the classpath are the following.

export CLASSPATH=$(JARS=(./lib/*.jar); IFS=:; echo "${JARS[*]}")
export CLASSPATH=$CLASSPATH:~/.m2/repository/org/apache/httpcomponents/httpclient/4.0.1/httpclient-4.0.1.jar
export CLASSPATH=$CLASSPATH:~/.m2/repository/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar
export CLASSPATH=$CLASSPATH:~/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
export CLASSPAHT=$CLASSPATH:~/ms_thesis/ONOS/httpcore-4.1.jar
#export CLASSPATH=$CLASSPATH:~/ms_thesis/ONOS/lib/httpclient-4.2.jar
export CLASSPATH=$CLASSPATH:~/google-gson-2.2.4/gson-2.2.4.jar

What jar file should I add to find "org/apache/http/params/SyncBasicHttpParams" I am very new to java and don't know how to debug this issue.


回答1:


org/apache/http/params/SyncBasicHttpParams class is under httpcore-4.1-alpha1.jar , which can be downloaded from

http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/httpcomponents/httpcore/4.1-alpha1/httpcore-4.1-alpha1.jar

In future if you need to find a jar for a class, then you can use this link, this is generally helpful:

http://www.findjar.com/




回答2:


According to the official documentation, the class that you seek is only in httpcore since 4.1. You'll want to pull a new JAR.




回答3:


In your case it seems to br you missing out some necessory jar files to include in your project

otherwise you any one of your linked is giving an exception mainly because of static method invocation or intialization




回答4:


Here's the link to get the jar file httpcore-4.1



来源:https://stackoverflow.com/questions/18246851/exception-in-thread-main-java-lang-noclassdeffounderror

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!