How can I make the classes from the module jdk.incubator.httpclient
visible at runtime?
Java 9 + Maven + HttpClient jdk.incubator.http.HttpClient
=> Maven build failing when using jdk.incubator.HttpClient
. Fixed with this question thanks to @nullpointer
=> Runtime stacktrace :
java.lang.NoClassDefFoundError: jdk/incubator/http/HttpClient
at com.foo.Bar.Bar.<clinit>(Bar.java:56) ~[?:?]
at java.lang.Class.forName0(java.base@9-Ubuntu/Native Method) ~[?:?]
at java.lang.Class.forName(java.base@9-Ubuntu/Class.java:374) ~[?:?]
Caused by: java.lang.ClassNotFoundException: jdk.incubator.http.HttpClient
at java.net.URLClassLoader.findClass(java.base@9-Ubuntu/URLClassLoader.java:388) ~[?:?]
at java.lang.ClassLoader.loadClass(java.base@9-Ubuntu/ClassLoader.java:486) ~[?:?]
at java.lang.ClassLoader.loadClass(java.base@9-Ubuntu/ClassLoader.java:419) ~[?:?]
at com.foo.Bar.Bar.<clinit>(Bar.java:56) ~[?:?]
at java.lang.Class.forName0(java.base@9-Ubuntu/Native Method) ~[?:?]
at java.lang.Class.forName(java.base@9-Ubuntu/Class.java:374) ~[?:?]
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${project.basedir}/resources</directory>
<includes>
<include>plugin.yml</include>
</includes>
</resource>
</resources>
<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>
As you can see, I am using the maven-shade-plugin
for my dependencies, but since jdk.incubator.http.HttpClient
is part of the JDK it is not included in my jar.
Trying to execute as:
java -jar --add-modules jdk.incubator.httpclient uhc-staging.jar
results into the following exception:
Error occurred during initialization of VM java.lang.module.ResolutionException: Module jdk.incubator.httpclient not found at java.lang.module.Resolver.fail(java.base@9-Ubuntu/Resolver.java:790) at java.lang.module.Resolver.resolveRequires(java.base@9-Ubuntu/Resolver.java:94) at java.lang.module.Configuration.resolveRequiresAndUses(java.base@9-Ubuntu/Configuration.java:370) at java.lang.module.ModuleDescriptor$1.resolveRequiresAndUses(java.base@9-Ubuntu/ModuleDescriptor.java:1986) at jdk.internal.module.ModuleBootstrap.boot(java.base@9-Ubuntu/ModuleBootstrap.java:263) at java.lang.System.initPhase2(java.base@9-Ubuntu/System.java:1927)
In the discussion, the detail brought out was that executing:-
java --list-modules
doesn't include jdk.incubator.httpclient
as a module which is the reason why the j.l.m.ResolutionException
is thrown. Hence, the solution to this shall be upgrading the JDK version installed to the latest release(which should include the incubator module) and then trying to run the application using the same command as suggested:-
java -jar --add-modules jdk.incubator.httpclient uhc-staging.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