Search code examples
twitter-streaming-apitwitter-hbc

java.lang.NoClassDefFoundError when using twitter hosebird


I am trying to use Twitter Streaming APIs so that I can filter some tweets real time and display. I am trying to follow https://github.com/twitter/hbc .

I am not used to using Maven, so I found this jar file at http://www.java2s.com/Code/Jar/h/Downloadhbccore140jar.htm . I simply added it to my build path and ran the following code.

 BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000);
     StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();

However, I get the following Error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest
    at com.twitter.hbc.core.endpoint.BaseEndpoint.<init>(BaseEndpoint.java:40)
    at com.twitter.hbc.core.endpoint.DefaultStreamingEndpoint.<init>(DefaultStreamingEndpoint.java:35)
    at com.twitter.hbc.core.endpoint.StatusesFilterEndpoint.<init>(StatusesFilterEndpoint.java:34)
    at com.twitter.hbc.core.endpoint.StatusesFilterEndpoint.<init>(StatusesFilterEndpoint.java:27)
    at StreamingApi.main(StreamingApi.java:36)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpUriRequest
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)

I even tried the same by using Maven to compile and converted the compiled classes to jar files and then use then. However, I get the same error. It looks like there are few internal dependencies which are not resolved.

Could someone please help me with it. Thanks in advance.


Solution

  • It is difficult to find each jar manually and add to the build path and test. So, I finally learned to use Maven - https://github.com/twitter/hbc .

    However, the Guava library was an old one and generated some errors. I used Guava-18.0 from https://code.google.com/p/guava-libraries/ and it works fine.