Creating the jdk.incubator.httpclient module visible at runtime

Question

How can I make classes from jdk.incubator.httpclient module visible at runtime?

What i use

Java 9 + Maven + HttpClient jdk.incubator.http.HttpClient

Problems

=> Error creating Maven 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) ~[?:?] 

Pom partition assembly

 <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 use 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.

Attempt to execute as:

  java -jar --add-modules jdk.incubator.httpclient uhc-staging.jar 

results in 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) 
+5
source share
1 answer

In the discussion, the inferred detail was that the execution: -

 java --list-modules 

does not include jdk.incubator.httpclient as the module, which causes jlmResolutionException be jlmResolutionException . Therefore, the solution to this should be to upgrade the version of the JDK installed to the latest version (including the incubator module), and then try to run the application using the same command as suggested: -

 java -jar --add-modules jdk.incubator.httpclient uhc-staging.jar 
+3
source

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


All Articles