简体   繁体   English

无法在 Maven 项目中使用 java.net.http 使用 Spring ZD52387880E17EA2281819721

[英]Unable to use java.net.http in Maven project using Spring Java 12

I am trying to use java.net.http library to use HTTP functions, however my IntelliJ compiler is not recognizing it.我正在尝试使用 java.net.http 库来使用 HTTP 函数,但是我的 IntelliJ 编译器无法识别它。

The error I receive on the package side: java: error: "invalid target release: 12"我在 package 端收到的错误:java:错误:“无效的目标版本:12”

in regards to the entire project here is another error that I receive: Plugin 'org.springframework.boot:spring-boot-maven-plugin:' not found关于整个项目,这是我收到的另一个错误: Plugin 'org.springframework.boot:spring-boot-maven-plugin:' not found

I have made sure I properly installed Java 12 as well as set it as the project & target bytecode version.我确保我正确安装了 Java 12 并将其设置为项目和目标字节码版本。 Im relatively new to coding in this environment so if there's anything I can do to better describe my question please let me know.我在这种环境中编码相对较新,所以如果我可以做些什么来更好地描述我的问题,请告诉我。

Here is the maven pom.xml file:这是 maven pom.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>io.rooseveltthedev</groupId>
    <artifactId>coronavirus-tracker</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>coronavirus-tracker</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>12</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

This is the code where I am having difficulty with the HTTP import:这是我在导入 HTTP 时遇到困难的代码:

import java.net.http.HttpClient;

public class CoronaVirusDataService {

    public static String VIRUS_DATA_URL = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv";


    public void fetchVirusData(){
        HttpClient client = HttpClient.newHttpClient();

    }

}

also I noticed there are some lines that refuse to go into the code formatting any remarks on how to fix that for future questions would be great.我还注意到有些行拒绝将 go 插入代码格式化任何关于如何解决未来问题的评论都会很棒。

This should be some maven project / compiler and/or class-path related issue in your development environment.这应该是您的开发环境中的一些 maven 项目/编译器和/或类路径相关问题。

I could not reproduce your error.我无法重现您的错误。 I am successfully using java.net.http.HttpClient with Spring Boot 2.4 and Java 12 (also Java 11 LTS.). I am successfully using java.net.http.HttpClient with Spring Boot 2.4 and Java 12 (also Java 11 LTS.). HttpClient is connecting getting back 200 status codes... HttpClient 正在连接取回 200 个状态代码...

Any issues you have is not related to java.net.http libraries with Spring Boot and Java 12...您遇到的任何问题都与带有 Spring 引导和 Java 12 的 java.net.http 库无关...

I would try to mvn compile and package using command line without the IDE.我会尝试使用没有 IDE 的命令行来 mvn 编译和 package。 Also, do you need spring boot dev-tools runtime dependency in your pom?另外,您的 pom 中是否需要 spring 引导开发工具运行时依赖项? Try to remove it...尝试删除它...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Heroku 部署构建失败 Java Spring 项目:package java.net.http 不存在 - Heroku deployment build failure Java Spring project : package java.net.http does not exist 无法将 java.net.http 导入我的 Android 项目 - Can't import java.net.http into my Android project java:找不到模块:java.net.http - java: module not found: java.net.http java.net.http 导入 - 未找到 - java.net.http import - not found 运行 maven 全新安装时未解析的 java.net.http 类 - Unresolved java.net.http classes while running maven clean install AWS SDK v2 SdkAsyncHttpClient 实现 使用 Java 11 java.net.http HttpClient sendAsync - AWS SDK v2 SdkAsyncHttpClient implementation Using Java 11 java.net.http HttpClient sendAsync 是否可以仅将 java.net.http 与 VSCode 和 Java 扩展插件一起使用? - Is it possible to use java.net.http with VSCode & Java Extension Plugin only? 如何测试 java.net.http (Java 11) 请求 BodyPublisher? - How to test java.net.http (Java 11) requests BodyPublisher? 当块到达时,如何使用 java.net.http 读取和打印分块的 HTTP 响应? - How do you read and print a chunked HTTP response using java.net.http as chunks arrive? Gradle构建找不到包&#39;java.net.http&#39; - Gradle build can't find the package 'java.net.http'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM