在Java9中将孵化器Http类与Maven结合使用 [英] Using Incubator Http Classes with Maven in Java9
问题描述
Java 9 + Maven + HttpClient(来自Java 9)jdk.incubator.http.HttpClient
Java 9 + Maven + HttpClient (from java 9) jdk.incubator.http.HttpClient
使用Maven构建项目时,出现以下错误
When building my project with maven I get the following error
[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
Foo
的第4行是
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不太满意,并且以前从未处理过孵化器类.我已经搜索了错误,但没有找到任何有用的信息.感谢您的帮助.
Sorry, if you think this has an oblivious fix, I am not very good with maven and never have had to deal with the incubator classes before. I have searched for the error but haven't found anything useful. Thanks for the help.
推荐答案
在创建模块时,您需要在包的最顶层创建一个module-info.java
类,该类之后应包含
While creating a module, you need to create a module-info.java
class at the topmost level of your packages which shall thereafter include
module yourModule {
requires jdk.incubator.httpclient;
}
确保模块jdk.incubator.httpclient
导出的软件包jdk.incubator.http
对您的模块可见.
ensuring that the package jdk.incubator.http
exported by the module jdk.incubator.httpclient
is visible to your module.
或者,要创建常规的类路径应用程序,您可以
Alternatively, to create a regular classpath application, you can
编译使用:-
<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>
运行,使用:-
java -jar --add-modules=jdk.incubator.httpclient yourJar.jar
这篇关于在Java9中将孵化器Http类与Maven结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!