我所使用的技术
Java 9 + Maven + HttpClient (从Java 9开始) jdk.incubator.http.HttpClient
问题
在使用maven构建我的项目时,我遇到了以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project Core: Compilation failure: Compilation failure:
[ERROR] Foo.java:[4,21] package jdk.incubator.http is not visible
< p > < code > Foo 的第四行是
import jdk.incubator.http.HttpClient;
Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.bar</groupId>
<artifactId>foo</artifactId>
<version>0.0.0-SNAPSHOT</version>
</parent>
<artifactId>Core</artifactId>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
注意
抱歉,如果您认为这有一个显而易见的解决方法,我并不擅长使用Maven,以前也从未处理过incubator类。我已经搜索了错误,但没有找到任何有用的信息。感谢您的帮助。
--add-modules jdk.incurbator.httpclient
进行编译和运行。 - Alan Bateman