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
Run Code Online (Sandbox Code Playgroud)
第4行Foo是
import jdk.incubator.http.HttpClient;
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
对不起,如果你认为这有一个不经意的修复,我对maven不太好,从来没有必须处理孵化器课程.我搜索了错误,但没有找到任何有用的东西.谢谢您的帮助.
在创建模块时,您需要module-info.java在包的最顶层创建一个类,此后将包含该类
module yourModule {
requires jdk.incubator.httpclient;
}
Run Code Online (Sandbox Code Playgroud)
确保jdk.incubator.http模块导出的包对模块jdk.incubator.httpclient可见.
或者,要创建常规类路径应用程序,您可以
编译使用: -
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
<compilerArgs>
<arg>--add-modules</arg>
<arg>jdk.incubator.httpclient</arg>
</compilerArgs>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
运行使用: -
java -jar --add-modules=jdk.incubator.httpclient yourJar.jar
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1541 次 |
| 最近记录: |