Java 9 + Maven + HttpClient (from java 9) jdk.incubator.http.HttpClient
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
Line 4 of Foo
is
import jdk.incubator.http.HttpClient;
<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>
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.
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;
}
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With