In thread "main" java.lang.NoClassDefFoundError: com/couchbase/client/core/env/CoreEnvironment


#1

Hi Team, I am new in Couchbase a nd trying simple application to retrieve the document from Couchbase

package couchbase.Connect;

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import rx.functions.Func1;

public class CouchbaseConnect {

private static String Bucketname = "tr-dev";
private static String bucketPassword = "23rates123$";	


 public static void main(String[] args) {
        System.out.print("hello world");
        Bucket buck = loginBucket();
        System.out.print(buck.get("/english/flying"));
    }
 
 public static Bucket loginBucket()	 {
	Cluster cluster = CouchbaseCluster.create("couchbase://10.107.13.106,10.107.10.172");
	return cluster.openBucket(Bucketname, bucketPassword);
 }

}

I am getting below error

hello worldException in thread “main” java.lang.NoClassDefFoundError: com/couchbase/client/core/env/CoreEnvironment
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at couchbase.Connect.CouchbaseConnect.loginBucket(CouchbaseConnect.java:21)
at couchbase.Connect.CouchbaseConnect.main(CouchbaseConnect.java:16)
Caused by: java.lang.ClassNotFoundException: com.couchbase.client.core.env.CoreEnvironment
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
… 11 more

I have search for this error , in one of the post they suggest to use latest Java Couchbase SDK but I am using 2.4.1 Java-Client.

Please help , I am missing any Reference JAR or any file.


#2

Are you using maven or a similar technology like gradle? It looks like one of the java clients mandatory dependencies (core-io) is not found.


#3

Hi Thanks for reply.
I am not using maven , can you please tell me How can I add missing reference & from where I can get the core-io.
Or If I convert the project to Maven project will it resolve the problem automatically.


#4

Converting your project to use Maven (or Gradle, my personal favorite) will likely fix the problem automatically, since these tools handle transitive dependencies (when one JAR depends on another JAR). It’s also a good idea for other reasons.

Alternatively, you can manually download the Couchbase client JAR and the transitive dependencies from their home on Maven Central. You’ll need these three:

java-client-2.5.9.jar
core-io-1.5.9.jar (this is the one you’re probably missing right now)
rxjava-1.3.4.jar

This list of dependencies and the required versions may change between releases, which is one more reason to use a build tool that handles transitive dependencies

Thanks,
David


#5

Thank you @david.nault , I have converted my project ito Maven project and copy paste the below XML tag in pom.xml

<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
<version>2.5.9</version></dependency>

After I saved , it automatically add the all dependence which you mentioned
Now I am able to connect Couchbase

Thank you very much.