0
I wanted to use Java 9 's HttpClient in my SpringBoot application. So I wrote the code for HttpClient in IntelliJ in a Maven project. The packages/module jdk.incubator.httpclient.*
was automatically included.
When I tried to run the application, it threw a compilation error saying
"package jdk.incubator.httpclient is declared in module jdk.incubator.httpclient, which is not in the module graph".
So I researched a little bit on the internet and a got a clue that creating a module file (module-info.java
) saying something like this :
module com.example {
requires jdk.incubator.httpclient;
}
would resolve the issue. So I did that, but other packages which were imported in other classes were now unresolved ( it could be resolved by adding its module to this class but adding all of them would be a painful task and it would be a repetition of what was already included in pom.xml
file).
So I researched a little bit more, and I got a clue that adding this ::
<compilerArgument>--add-modules=jdk.incubator.httpclient</compilerArgument>
to the configuration section in maven-compiler-plugin
of pom.xml
would resolved the issue.
After taking the last step the project compiled successfully but when I tried to run the application it threw a runtime error saying ,
java.lang.ClassNotFoundException: jdk.incubator.http.HttpRequest
and
java.lang.NoClassDefFoundError: jdk/incubator/http/HttpRequest
I tried to look for solutions online but was not able to find it, one person faced the same issue , he got it partially resolved using the last step but got the same runtime error as me, he asked for the solution but did not receive any.
Is it possible to run HttpClient , HttpRequest in SpringBoot-Maven application, if yes , then how ? Please guide.
In the end I had to use HttpURLConnection class for my purpose. – lakhansoren – 2019-09-13T12:52:52.750