So i want to try the http client
package com.company;
import jdk.incubator.http.HttpClient;
public class Main {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient();
}
}
And my module info looks like this
module com.company {
requires jdk.incubator.httpclient;
}
But i get java.lang.NoClassDefFoundError: jdk/incubator/http/HttpClient
And I don't really understand why. My java version is "build 9-ea+ 169" and I use the latest version of IntelliJ idea (2017.1.3). I looked into this answer and it looks like I have to just add requirement into a file, but it doesn't work for some reason.
NoClassDefFoundError, which means the Class Loader file responsible for dynamically loading classes can not find the . class file. So to remove this error, you should set your classpath to the location where your Class Loader is present.
ClassNotFoundException is an exception that occurs when you try to load a class at run time using Class. forName() or loadClass() methods and mentioned classes are not found in the classpath. NoClassDefFoundError is an error that occurs when a particular class is present at compile time, but was missing at run time.
The NoClassDefFoundError is a runtime error in Java that occurs if the Java Virtual Machine (JVM) or a ClassLoader instance attempts to load the definition of a class that could not be found. The class definition exists at compile-time but is not available at runtime.
works fine for me if I use --add-modules jdk.incubator.httpclient
as the start-up parameter.
HttpClient client = HttpClient.newHttpClient();
client.executor().execute(() -> System.out.println("Here")); // prints Here
If you say that your module requires it, does not mean it will be included; at it is not included by default.
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