This code was previously working for me under Server 3.0.1.
ClusterManager manager = new ClusterManager(local_hosts, username, password); Object[] list = manager.listBuckets().toArray(); if (manager.listBuckets().size() == 0) { manager.createNamedBucket(BucketType.COUCHBASE, "mybucket", 100, 1, "", true); System.out.println("Mybucket bucket created."); } else { System.out.println("Mybucket bucket already exists."); }
When I updated to Server 4.0.0, I found this function was broken and needed to be rewritten with the updated .client.java. classes.
I’ve tried many different patterns based on the “Hello World” topic and other topics in the documentation. I’ve tried with and without defining and calling CouchbaseEnvironment, with and without 127.0.0.1 specified as the URL string of the server in CouchbaseCluster.create(). The code below is only the last of a long string of attempts to make this work.
NetBeans says I have imported all of the necessary classes, and that it thinks my syntax is correct.
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.create(); Cluster myapp = CouchbaseCluster.create(env); ClusterManager cluster = myapp.clusterManager(username, password); if (cluster.hasBucket("mybucket")) { System.out.println("Mybucket bucket already exists."); } else { DefaultBucketSettings bucketSettings = new DefaultBucketSettings.Builder() .type(BucketType.COUCHBASE) .name("mybucket") .password("") .quota(250) // megabytes .replicas(1) .indexReplicas(true) .enableFlush(true) .build(); cluster.insertBucket(bucketSettings); System.out.println("Mybucket bucket created."); }
In every case, when I try to run my app, it throws some variation of the following error message with “Unknown Source” everywhere.
Other logs show that everything up to this point in the code is executing correctly.
Exception in thread “Thread-0” java.lang.NoClassDefFoundError: rx.Subscriber
at java.lang.ClassLoader.(Unknown Source)
at java.lang.ClassLoader.(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.(Unknown Source)
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)
at com.couchbase.client.core.env.DefaultCoreEnvironment$Builder.(Unknown Source)
at com.couchbase.client.java.env.DefaultCouchbaseEnvironment$Builder.(Unknown Source)
at com.couchbase.client.java.env.DefaultCouchbaseEnvironment.(Unknown Source)
at com.couchbase.client.java.env.DefaultCouchbaseEnvironment.create(Unknown Source)
at omnibazaar.GreetingServer.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: rx.Subscriber
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)
… 17 more
This isn’t a complicated function. I’m only trying to check if a specific bucket exists, and create it if it doesn’t. What in the heck am I doing wrong?
Any help will be greatly appreciated.