'java.net.http does not exist error on JDK11

Its a command line program. Was trying to send a POST call using java.net.http module but I keep getting the following error.

java: package java.net.http does not exist
C:\Users\dell>java -version
java version "11.0.10" 2021-01-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.10+8-LTS-162)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.10+8-LTS-162, mixed mode)

Intellij project SDK - java version 11.0.10

Code -

import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.serphouse.com/serp/live"))
                .POST(HttpRequest.BodyPublishers.ofString(content))
                .header("Content-Type", "application/json")
                .header("Authorization", "Bearer xZWmYW3fJ0L0juYQrZ6br3etoNhF1iGVhwrWxRlwbhGWflzDeOR0tEPAiJQqJFxc")
                .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());


Solution 1:[1]

Got it to work. Just updated Intellij. Thank you @xerx593 and @alain.janinm

Solution 2:[2]

I got it fixed by following the IDE suggestion which was to convert the language level to 11 and it added following plugin in pom.xml

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Asfand