Trouble creating cluster after updating to Server 4.0

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.

It seems you have a classpath issue. The compiler cannot find this class: rx.Subscriber
Can you show us how you compile and run your code?

Did you upgrade from a 1.4.x SDK to a 2.x SDK by any chance? And are you using Maven (or a Maven-compatible dependency manager) to build your project? As ldoguin said, this sounds like a classpath / build issue.

Thank you both for responding.

I do have the 2.2.8 SDK, and am importing several classes from the 2.2.8 com.couchbase.client.java.

The project runs and builds without errors from within NetBean 8.1. Then, I am compiling and packaging the application using the latest version of Excelsior JET (and their associated packager). When I “test run” from within Excelsior, it seems to load the dependencies and output the correct response. But this code path that checks for and creates the bucket only gets exercised in specific circumstances. So, I haven’t been alerted about missing dependencies until the error messages occur when I run the compiled application.

I don’t have Maven installed. I have just installed the Maven plug-in for NetBeans but haven’t yet figured out what to do with it.

Could this be a case where Excelsior needs some includes that NetBeans doesn’t ask for?

Thank you for your help with this.

Yeah you probably need to manually add all dependencies. There is also a JET Maven plug-in that could be worth looking into: https://github.com/excelsior-oss/excelsior-jet-maven-plugin

Adding all of the dependencies from the SDK did the trick.

Thank you for your help.

(I’ll know better next time.)