title: Java 9 HttpClient java.lang.NoClassDefFoundError: jdk/incubator/http/HttpClient
body: <p>I am trying to use the HttpClient from incubator in Java 9 maven project.  I am not getting any Compilation issue. The project builds successfully. But when I try to run the Main class, it gives me the following exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: jdk/incubator/http/HttpClient
  at java9.http_client.Main.main(Main.java:18)
  Caused by: java.lang.ClassNotFoundException: jdk.incubator.http.HttpClient
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
  at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)....
  </code></pre>
  
  <p>My code is just a module-info file and a Main class that just calls google.com and tries to read the response:</p>
  
  <p><strong>module-info.java</strong></p>
  
  <pre><code>module java9.http_client {   
      requires jdk.incubator.httpclient;
  }
  </code></pre>
  
  <p><strong>Main.java</strong></p>
  
  <pre><code>public final class Main {
  
  public static void main(String[] args) {
   try {
          HttpClient client = HttpClient.newHttpClient();
          URI httpURI = new URI("http://www.google.com/");
          HttpRequest request = HttpRequest.newBuilder(httpURI).GET().build();
          HttpResponse&lt;String&gt; response = client.send(request, HttpResponse.BodyHandler.asString());
  
          String responseBody = response.body();
          int responseStatusCode = response.statusCode();
          System.out.println(responseBody + "\n" + responseStatusCode);
  
      } catch (URISyntaxException | IOException | InterruptedException e) {
          throw new RuntimeException("Unable to run Java 9 Http Client examples", e);
      }
  }
  }
  </code></pre>
  
  <p><strong>pom.xml</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.javacodegeeks.java9&lt;/groupId&gt;
  &lt;artifactId&gt;http_client&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;Java9HttpClient&lt;/name&gt;
  &lt;description&gt;Java Http Client example&lt;/description&gt;
  &lt;properties&gt;
      &lt;java-version&gt;1.9&lt;/java-version&gt;
  
      &lt;maven-compiler-plugin-version&gt;3.6.1&lt;/maven-compiler-plugin-version&gt;
      &lt;maven-shade-plugin-version&gt;3.0.0&lt;/maven-shade-plugin-version&gt;
  &lt;/properties&gt;
  
  &lt;build&gt;
      &lt;pluginManagement&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${maven-compiler-plugin-version}&lt;/version&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${maven-shade-plugin-version}&lt;/version&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;source&gt;${java-version}&lt;/source&gt;
                  &lt;target&gt;${java-version}&lt;/target&gt;
                  &lt;verbose&gt;true&lt;/verbose&gt;
  
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;phase&gt;package&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;shade&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;transformers&gt;
                              &lt;transformer
                                  implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&gt;
                                  &lt;mainClass&gt;com.javacodegeeks.java9.http_client.Main&lt;/mainClass&gt;
                              &lt;/transformer&gt;
                          &lt;/transformers&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p>What am I missing? I found various articles about this but they are all doing it in this way.</p>
  
  <p>Any help is appreicated. Thanks!</p>
  
  <p><strong>Command executed when using --add-modules</strong></p>
  
  <pre><code>cd /home/mansi/NetBeansProjects/java9-http-client; JAVA_HOME=/home/mansi/jdk-9 /home/mansi/netbeans-dev-201709070001/java/maven/bin/mvn "-Dexec.args=--add-modules=jdk.incubator.httpclient -classpath %classpath java9.http_client.Main" -Dexec.executable=/home/mansi/jdk-9/bin/java -Dexec.classpathScope=runtime org.codehaus.mojo:exec-maven-plugin:1.5.0:exec
  </code></pre>
  
  <p><strong>When not using --add-modules</strong></p>
  
  <pre><code>cd /home/mansi/NetBeansProjects/java9-http-client; JAVA_HOME=/home/mansi/jdk-9 /home/mansi/netbeans-dev-201709070001/java/maven/bin/mvn "-Dexec.args=-classpath %classpath java9.http_client.Main" -Dexec.executable=/home/mansi/jdk-9/bin/java -Dexec.classpathScope=runtime org.codehaus.mojo:exec-maven-plugin:1.5.0:exec
  </code></pre>