Using classes of Http incubators with Maven in Java9

What i use

Java 9 + Maven + HttpClient (from java 9) jdk.incubator.http.HttpClient

Problem

When creating 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 

Line 4 of Foo equals

 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> 

Note

Sorry if you think this is a forgotten solution, I am not very good with maven and have never been involved in incubator classes before. I was looking for an error, but did not find anything useful. Thanks for the help.

+4
source share
1 answer

When creating a module, you need to create the module-info.java class at the very top level of your packages, which will then include

 module yourModule { requires jdk.incubator.httpclient; } 

so that the jdk.incubator.http package exported by the jdk.incubator.httpclient module is visible to your module.

Alternatively, to create a regular pathpath application, you can

Compile using: -

 <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 using: -

 java -jar --add-modules=jdk.incubator.httpclient yourJar.jar 
+5
source

Source: https://habr.com/ru/post/1273614/


All Articles