title: HttpClient not present at run time
body: <p>I am trying to create a rest client. I am using Spring. I have instantiated <code>HttpComponentsClientHttpRequestFactory</code>, which uses <code>org.apache.http.client.HttpClient</code> inside. Maven compilation is Ok, but when I run the project I get <code>java.lang.ClassNotFoundException: org.apache.http.client.HttpClient.</code></p>
  
  <p>Furthermore, when I place the mouse pointer on top of the import of HttpClient, I get <code>sun.net.www.http.HttpClient</code>, which is in rt.jar, instead of getting <code>org.apache.http.client.HttpClient</code>. I have checked that HttpClient truly does not exist in any other package. I know that I can find <code>org.apache.http.client.HttpClient</code> in other artifacts, such as</p>
  
  <pre><code>&lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
  &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
  &lt;version&gt;4.0-alpha3&lt;/version&gt;
  </code></pre>
  
  <p>However, I am not sure whether this should be right, since Spring itself does not seem to resort to this (I cannot see it does when I check the dependency hierarchy in the pom file).</p>
  
  <p>In any case, I wonder why an import such as <code>org.apache.http.client.HttpClient</code> should resort to <code>sun.net.www.http.HttpClient</code>. I guess that the fact that the latter is in rt.jar is related to HttpClient not being available at run time.
  If you want to check about all this, this is my pom file, it is quite simple:</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;xxx.xxx&lt;/groupId&gt;
      &lt;artifactId&gt;xxx&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.5.RELEASE&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>Thanks a lot.</p>
  
  <p><strong>Edit:</strong>
  The code is quite simple, you just need to instantiate the class <code>HttpComponentsClientHttpRequestFactory</code>. There is more code, but you only need this to obtain the exception.</p>
  
  <pre><code>@SpringBootApplication
  public class Client {
  
      public static void main(String args[]) {
          SpringApplication.run(Client.class);
      }
  
      @Bean
      public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
          RestTemplate restTemplate = restTemplateBuilder.build();
          ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
          return restTemplate;
      }
  </code></pre>