Why IntelliJ IDEA doesn't see HttpClients?
Asked Answered
I

2

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

Isocrates answered 20/4, 2015 at 2:14 Comment(9)
I assumed you imported the class right?Funderburk
Why did you specify test scope in the maven dependency?Washin
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?Isocrates
Trying import "import org.apache.*;" - but it is red. Looks like I should add some other librariesIsocrates
Put your cursor on HttpClients. You should see a small blue dialog popup suggesting pressing Alt + Enter to select package to importGoldy
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.1Isocrates
have you tried 'Synchronize 'pom.xml'' or 'Maven > Reimport' from context menu on your pom.xml?Welcy
Yes, before I resolved the problem (see an accepted answer below) I've tried to reimport, but that did not helpIsocrates
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.Iron
I
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 :)

Isocrates answered 21/4, 2015 at 3:46 Comment(0)
M
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.

Mercaptide answered 13/6, 2019 at 6:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.