10

I've added following into dependencies section of my pom.xml:

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.4.1</version>
        <scope>test</scope>
    </dependency>

But when I add the 1st line of "Quick start guide" (http://hc.apache.org/httpcomponents-client-4.4.x/quickstart.html):

CloseableHttpClient httpclient = HttpClients.createDefault();

IntelliJ IDEA highlights "HttpClients" and tells me:

Cannot resolve symbol 'HttpClients'

It looks like I have mistake with configuration. What exactly is wrong? please advise how to add support for HttpClients into the project?

Thanks!

P.S. Learned a bit more, looks like "" is redundant and wrong for this case, I removed it but that didn't help: still non-compilable.

EDIT: If I put cursor to 'HttpClients' and hit "Alt-enter" the pop-up doesn't contain any class to import. See screenshot: enter image description here

skaffman
  • 398,947
  • 96
  • 818
  • 769
Budda
  • 18,015
  • 33
  • 124
  • 206
  • I assumed you imported the class right? – Anubian Noob Apr 20 '15 at 02:15
  • Why did you specify test scope in the maven dependency? – skaffman Apr 20 '15 at 02:20
  • Removed scope already (copy past from 'mockito' dependency). And regarding import - no, I didn't do any import. Not sure what is the proper package name and expected IntelliJ IDEA to suggest the proper one. Should I do that manually? – Budda Apr 20 '15 at 02:23
  • Trying import "import org.apache.*;" - but it is red. Looks like I should add some other libraries – Budda Apr 20 '15 at 02:25
  • Put your cursor on `HttpClients`. You should see a small blue dialog popup suggesting pressing Alt + Enter to select package to import – Jason Apr 20 '15 at 02:25
  • I've tried, it has not "Imports". I also tried to "Find JAR on web", found few other libraries, added them to pom.xml - but still no any success with compilation. New projects added are: org.apache.httpcomponents:httpcore:4.1; org.apache.httpcomponents:httpclient:4.1.1 – Budda Apr 20 '15 at 02:33
  • have you tried 'Synchronize 'pom.xml'' or 'Maven > Reimport' from context menu on your pom.xml? – arghtype Apr 20 '15 at 10:08
  • Yes, before I resolved the problem (see an accepted answer below) I've tried to reimport, but that did not help – Budda Apr 23 '15 at 18:25
  • There is a floating button says `Load Maven Changes` on top right of window or simply shortcut `cmd`+`shift`+`i`, this would load dependency changes to work with IntelliJ, this could also help resolving those already resolved yet **red** dependency. – ychz Jun 07 '20 at 16:52

2 Answers2

4

It looks like my IntelliJ had issues with caching, cleaning cache with following re-importing of the project helped.

I found tips on that here: IntelliJ inspection gives "Cannot resolve symbol" but still compiles code

P.S. Though few other project were broken as a result of this action. Looks like I need to keep learning :)

Community
  • 1
  • 1
Budda
  • 18,015
  • 33
  • 124
  • 206
1

Download the jar file from https://jar-download.com/artifacts/org.apache.httpcomponents/httpclient/4.5.6/source-code

Extract the .jar file name httpclient-4.5.6.jar. Form a directry name lib under your project and import this .jar file to it. Right click your .jar file and click addtolibrary.

H Soora
  • 47
  • 5