title: java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE from Mashape Unirest in Java application
body: <p>I have a Maven Java project that uses <a href="http://unirest.io/java.html" rel="noreferrer"><strong>Mashape Unirest</strong></a> for sending HTTP requests to other URLs. I am currently writing an integration test (using <strong>TestNG</strong>) that sends a normal HTTP request using Unirest. When I run the integration test through Maven (via the Failsafe plugin), the request is sent out successfully. However, when I try to run the integration test via Eclipse, I keep on getting the following error:</p>
  
  <pre><code>FAILED: getCurrentTimeTest
  java.lang.NoSuchFieldError: INSTANCE
      at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.&lt;init&gt;(DefaultHttpRequestWriterFactory.java:52)
      at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.&lt;init&gt;(DefaultHttpRequestWriterFactory.java:56)
      at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.&lt;clinit&gt;(DefaultHttpRequestWriterFactory.java:46)
      at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.&lt;init&gt;(ManagedHttpClientConnectionFactory.java:72)
      at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.&lt;init&gt;(ManagedHttpClientConnectionFactory.java:84)
      at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.&lt;clinit&gt;(ManagedHttpClientConnectionFactory.java:59)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.&lt;init&gt;(PoolingHttpClientConnectionManager.java:487)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.&lt;init&gt;(PoolingHttpClientConnectionManager.java:147)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.&lt;init&gt;(PoolingHttpClientConnectionManager.java:136)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.&lt;init&gt;(PoolingHttpClientConnectionManager.java:112)
      at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
      at com.mashape.unirest.http.options.Options.refresh(Options.java:41)
      at com.mashape.unirest.http.options.Options.&lt;clinit&gt;(Options.java:27)
      at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:141)
      at com.mashape.unirest.http.HttpClientHelper.requestAsync(HttpClientHelper.java:80)
      at com.mashape.unirest.request.BaseRequest.asStringAsync(BaseRequest.java:56)
      at ...
  </code></pre>
  
  <p>I am also able to reproduce this error using a basic Java application script.</p>
  
  <p>I have made sure that the dependencies I am using in my <em>pom.xml</em> file are the latest and greatest, as seen below:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.mashape.unirest&lt;/groupId&gt;
      &lt;artifactId&gt;unirest-java&lt;/artifactId&gt;
      &lt;version&gt;1.3.5&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
      &lt;version&gt;4.3.2&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpasyncclient&lt;/artifactId&gt;
      &lt;version&gt;4.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpmime&lt;/artifactId&gt;
      &lt;version&gt;4.3.2&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.json&lt;/groupId&gt;
      &lt;artifactId&gt;json&lt;/artifactId&gt;
      &lt;version&gt;20140107&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpcore&lt;/artifactId&gt;
      &lt;version&gt;4.3.2&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I have also checked out the source code of <code>BasicLineFormatter.java</code>, both from the source file downloaded to Eclipse and from <a href="https://github.com/apache/httpcore/blob/4.3.x/httpcore/src/main/java/org/apache/http/message/BasicLineFormatter.java" rel="noreferrer">Apache's Httpcore Github repo</a>. In the Github repo, notice how the <code>INSTANCE</code> field is defined for the 4.3.x branch and the trunk branch,  but not in older branches like 4.2.x. However, I am indeed using version <code>4.3.2</code> in my project, so I should be using a JAR file for Httpcore that has the latest version of <code>BasicLineFormatter</code>. I know that, based on the Maven Dependencies JAR files that are in my project, that I am indeed using the latest versions of these Apache dependencies, not the older versions specified as downstream dependencies of my project.</p>
  
  <p>I have checked other various SOF and blog posts about this issue, such as <a href="https://stackoverflow.com/questions/19562984/mashape-unirest-java-java-lang-noclassdeffounderror">Mashape Unirest Java : java.lang.NoClassDefFoundError</a> and <a href="http://blog.mashape.com/post/69639276345/using-unirest-java-for-your-android-projects" rel="noreferrer">this blog post too</a>, but they all seem to be talking about solving the NoSuchFieldError problem for <em>Android</em>. However, I'm dealing with a standalone Java application, not an Android application.</p>
  
  <p>I am at a loss in determining how to troubleshoot this issue. Anyone have any idea what I need to do?</p>
  
  <h3>UPDATE</h3>
  
  <p>Instead of showing my test case, I will reduce the illustration of a reproduction of this problem to just a simple one-liner Java application, because the problem exists with any Java application or test case run through Eclipse, not just one particular test:</p>
  
  <pre><code>System.out.println(Unirest.get("http://www.google.com").asStringAsync().get().getBody());
  </code></pre>
  
  <p>Normally, this should print the HTML of the Google home page, but I instead get the NoSuchFieldError stack trace.</p>
  
  <hr>
  
  <h2>FIXED!</h2>
  
  <p>The problem was that the <em>AWS SDK</em> (it's on my classpath because I'm developing for Elastic Beanstalk) had a conflicting JAR file. Using Oleg's solution (thanks BTW), I printed the following output in a unit test:</p>
  
  <pre><code>jar:file:/some/path/aws-java-sdk/1.7.1/third-party/httpcomponents-client-4.2.3/httpcore-4.2.jar!/org/apache/http/message/BasicLineFormatter.class
  </code></pre>
  
  <p>I'll have to rearrange my classpath so that AWS SDK is no longer conflicting.</p>