I have a Maven Java project that uses an HttpClient to execute HTTP requests. On my local Java Web Server everything works fine. But after I deploy it to the SAP Hana Cloud Platform I get the following error:
java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:493)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
at com.sap.hana.cloud.odata.service.OlingoSampleApp.getHttpclient(OlingoSampleApp.java:382)
at com.sap.hana.cloud.odata.service.OlingoSampleApp.getCsrfToken(OlingoSampleApp.java:374)
at com.sap.hana.cloud.odata.service.ODataCalls.doGet(ODataCalls.java:163)
...
My dependency looks like this:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
<scope>compile</scope>
</dependency>
According to this question java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE from Mashape Unirest in Java application I tried to use the following code to get the ClassLoader Ressource.
ClassLoader classLoader = this.getClass().getClassLoader();
URL resource = classLoader.getResource("org/apache/http/impl/client/HttpClientBuilder.class");
return resource;
and it returns the following
"jar:file:/some/path/WEB-INF/lib/httpclient-4.3.5.jar!/org/apache/http/impl/client/HttpClientBuilder.class"
You can see that the jar-versions are the same. Every similar question I looked at had incoherent jar-versions as the source of failure. Could there be another reason for this error?
Update
After the discussion in the comments I'll update my question:
Dependency tree:
So now I could see the version conflict and I removed the neo-java-web-api
. The classLoader now returns version 4.3.2 again. But I still get the error from the beginning.
The new, complete dependency tree without the neo-java-web-api
now looks like the following: