Issue
I'm trying to use CouchDB with JAVA. It's horrible!!! Here the code i found on the net:
package project.couchdb;
import java.net.MalformedURLException;
import org.ektorp.CouchDbConnector;
import org.ektorp.CouchDbInstance;
import org.ektorp.http.HttpClient;
import org.ektorp.http.StdHttpClient;
import org.ektorp.impl.StdCouchDbConnector;
import org.ektorp.impl.StdCouchDbInstance;
import org.ektorp.support.DesignDocument;
public class CouchConnect {
public static void main(String[] args) throws MalformedURLException{
//connection
HttpClient client = new StdHttpClient.Builder().url("http://127.0.0.1:5984").build();
CouchDbInstance dbIstance = new StdCouchDbInstance(client);
//database
CouchDbConnector db = new StdCouchDbConnector("test", dbIstance);
db.createDatabaseIfNotExists();
//document
DesignDocument doc = new DesignDocument("test_doc");
db.create(doc);
}
}
The errors:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/impl/client/cache/CacheConfig
at org.ektorp.http.StdHttpClient$WithCachingBuilder.withCaching(StdHttpClient.java:533)
at org.ektorp.http.StdHttpClient$Builder.build(StdHttpClient.java:523)
at project.couchdb.CouchConnect.main(CouchConnect.java:18)
Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.client.cache.CacheConfig
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
I've just added some .jar because console gave me error like 'ClassNotFoundException' but this time i can't find the .jar file to add. Have someone te link to download the .jar or any other solution?
PS: I'm using eclipse on windows 10 if it's relevant
After adding the remaining .jar i have thhis errors:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.client.utils.URLEncodedUtils.parsePathSegments(Ljava/lang/CharSequence;)Ljava/util/List;
at org.apache.http.impl.client.cache.CacheKeyGenerator.getRequestUri(CacheKeyGenerator.java:78)
at org.apache.http.impl.client.cache.CacheKeyGenerator.getURI(CacheKeyGenerator.java:118)
at org.apache.http.impl.client.cache.CacheInvalidator.flushInvalidatedCacheEntries(CacheInvalidator.java:86)
at org.apache.http.impl.client.cache.BasicHttpCache.flushInvalidatedCacheEntriesFor(BasicHttpCache.java:361)
at org.apache.http.impl.client.cache.CachingHttpClient.flushEntriesInvalidatedByRequest(CachingHttpClient.java:596)
at org.apache.http.impl.client.cache.CachingHttpClient.execute(CachingHttpClient.java:457)
at org.apache.http.impl.client.cache.CachingHttpClient.execute(CachingHttpClient.java:345)
at org.ektorp.http.StdHttpClient.executeRequest(StdHttpClient.java:177)
at org.ektorp.http.StdHttpClient.executeRequest(StdHttpClient.java:192)
at org.ektorp.http.StdHttpClient.head(StdHttpClient.java:146)
at org.ektorp.http.RestTemplate.head(RestTemplate.java:109)
at org.ektorp.impl.StdCouchDbInstance.checkIfDbExists(StdCouchDbInstance.java:98)
at org.ektorp.impl.StdCouchDbInstance.createDatabaseIfNotExists(StdCouchDbInstance.java:63)
at org.ektorp.impl.StdCouchDbInstance.createDatabaseIfNotExists(StdCouchDbInstance.java:59)
at org.ektorp.impl.StdCouchDbConnector.createDatabaseIfNotExists(StdCouchDbConnector.java:413)
at project.couchdb.CouchConnect.main(CouchConnect.java:23)
Solution
You also need httpclient-cache in your list of libraries.
This seems pretty early to declare it "horrible".
Answered By - nitind