java version "1.7.0_71"
Gradle 2.1
Hello,
UPDATE:
The dependencies
gradle dependencies | grep httpcore
| +--- org.apache.httpcomponents:httpcore:4.3.3
| +--- org.apache.httpcomponents:httpcore:4.3.3
| +--- org.apache.httpcomponents:httpcore:4.3.3
| +--- org.apache.httpcomponents:httpcore:4.3.3
| | | | | +--- org.apache.httpcomponents:httpcore:4.1 -> 4.3.3
| +--- org.apache.httpcomponents:httpcore:4.3.3
| | | | | +--- org.apache.httpcomponents:httpcore:4.1 -> 4.3.3
Does this mean I have 4.1 that is a soft link to 4.3.3? Seems strange as when I print out what the class loader is loading it seems to load 4.3.3: /home/steve/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar
seems very strange.
I keep getting this error when I try and run my httpClient. Everything compiles ok.
java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52
My code is very simple, removed not important code to keep it small:
public class GenieClient {
private CloseableHttpClient mClient;
public GenieClient() {
ClassLoader classLoader = GenieClient.class.getClassLoader();
URL resource = classLoader.getResource("org/apache/http/message/BasicLineFormatter.class");
log.log(Level.INFO, "resource: " + resource);
mClient = HttpClientBuilder.create().build();
}
public int sendRequest() {
int responseCode = -1;
try {
HttpResponse response = mClient.execute(new HttpPost("http://www.google.com"));
responseCode = response.getStatusLine().getStatusCode();
}
catch(IOException ex) {
log.log(Level.SEVERE, "IOException: " + ex.getMessage());
}
return responseCode;
}
}
The output I get from the classLoader is this:
INFO: resource: jar:file:/home/steve/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar!/org/apache/http/message/BasicLineFormatter.class
I am using gradle as my build tool and have set the dependencies like this in my build.gradle
file:
dependencies {
compile 'org.apache.httpcomponents:httpclient:4.3.6'
}
I have also tried to include the following httpcore, but still get the same error:
compile 'org.apache.httpcomponents:httpcore:4.4'
Everything builds ok, its only when I run my httpClient,
Many thanks for any suggestions,