10

The following

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

can't be resolved. I downloaded the Apache Http packages and imported them via the external jars option, but it still won't get resolved. In Android it seems to work, guessing its in the SDK, but here I'm not doing Android. Did I get the wrong packages?

I believe this is the link:

Apache

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
Fasih Awan
  • 1,891
  • 4
  • 17
  • 24
  • 2
    Sometimes after importing external libraries, I have to refresh dependencies or close and open the project to get the eclipse errors to go away. – John Moses Aug 29 '12 at 22:21
  • Good point. I often do an Eclipse "Project, Clean" for precisely that reason. – paulsm4 Aug 30 '12 at 02:06

3 Answers3

13

It sounds OK:

  1. The .jar file in question should be something like httpcore-4.0.1.jar. Please confirm the name.

  2. Adding this to "External Libraries" is absolutely the correct thing to do.

  3. For compiling in the Eclipse IDE, you must:

    • Select your project

    • Select "Build Path" > "Add External Libraries"

  4. For running in the Eclipse IDE, you must

    • Select "Run" > "Run configurations".
      Choose your (Java Application?) configuration.

    • Select "Classpath" > "Add External Jar"

  5. For running outside of the Eclipse IDE, you must make sure the .jar file is present and your -cp (Classpath) argument is set correctly.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • 2
    Thanks paulsm4. Google removed the support for Apache HTTP Client, according to this:https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client You yourself have to download a copy of httpcore-4.0.1.jar from http://www.java2s.com/Code/Jar/h/Downloadhttpcore401jar.htm Import it into your libs folder. That will solve the problem. Proguard exception: -dontwarn org.apache.http.** -dontwarn com.android.volley.toolbox.** – Mangi Morobe Oct 06 '15 at 03:03
1

After dragging the jars into my project I was having the same issue.

Right-click on the jar and selecting Build-path -> Add-to-Build-Path worked for me.

anthonybell
  • 5,790
  • 7
  • 42
  • 60
0

If you first added those JARs to an Android project, but now want to use them in another (non-Android) project, make sure you've imported the JARs into this other project. In Eclipse, each project maintains its own build classpath settings, so importing JARs into one project does not automatically make them available to other projects.

E-Riz
  • 31,431
  • 9
  • 97
  • 134
  • That wasn't what I meant. I was just saying in the case of Android all these packages are available so I didn't have to import their respective jars – Fasih Awan Aug 30 '12 at 00:07
  • @E-Riz What to do if I want to add a jar so that it can be available to all the project, do I have to add it in plugin folder - C:\eclipse-jee-luna-R-win32\eclipse\plugins ?? – Nikhil Sep 27 '14 at 16:47