1

I was trying to import HttpClient class in my code from java.net.http package. Turns out, this package is not present when I try to import.

I did some research and found that java.net.http was included from JDK 9 onwards. I have JDK 15 installed in my system but still I can't import this package.

IDE: Eclipse JDK: 15.0.2 JRE: 1.8.281

Installed JRE's JDK Compliance Level

Could someone help me with this issue?

Thanks, Ishan Pathak

2
  • 1
    Please point the jre also to the same version as JDK. Also which version of eclipse are you using? Commented Feb 22, 2021 at 8:50
  • glad that it worked for you :) Commented Feb 23, 2021 at 12:11

1 Answer 1

1

The HttpClient class was added to Java 11 and later.

You will need to configure your project within your IDE to compile for Java 11 or later. And you’ll need to configure your IDE to run with Java 11 or later when running your code.

I don’t know what you meant by JRE of Java 8 in addition to Java 15. You may have multiple versions of Java installed. That is okay, but you have to tell your IDE which one to use for your project.

Configuring for all the major IDEs ( IntelliJ, NetBeans, Eclipse ) has been covered many times already on Stack Overflow. So search to learn more. For example, here.


To learn more about the new HttpClient classes, see these posts on the OpenJDK.java.net site.

Sign up to request clarification or add additional context in comments.

1 Comment

Updating my JRE path to JDK 15 directory solved the issue. Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.