ClassNotFoundException while connecting to Couchbase

54 Views Asked by At

From a webapp I want to connect to a couchbase cluster. The cluster was installed via docker container and just exposes port 8091. I can correctly connect from a web browser.

Then in my webapp this code gets executed:

Cluster couchbase = Cluster.connect("couchbase://localhost:8091=manager", user, password);

But at runtime I get log output like this:

ClassNotFoundException: sun.misc.Unsafe from [Module "deployment.myproject.war" from Service Module Loader]

I played around with the connection string, with port mapping etc but the error remains the same. I also played around with the Java module system, created a module-info.java file in my project root and added

module myproject {
    requires jdk.unsupported;
    requires jakarta.batch;
    requires com.couchbase.client.java;
    requires org.apache.logging.log4j;
    requires java.xml;
    requires org.apache.commons.csv;
    requires org.apache.commons.io;
}

It meanwhile seems to me that the Couchbase Java SDK does not declare a module. Here is the SDK I used, but I also checked versions 3.5.1, 3.5.0, 3.4.11 and 3.3.4.

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

Then I edited my Wildfly startup script to contain

set "JAVA_OPTS=%JAVA_OPTS% --add-opens jdk.unsupported/sun.misc=deployment.myproject.war --add-opens jdk.unsupported/sun.misc=ALL-UNNAMED"

But all this did not help. Ah yes, I am running all of this on

Windows 10 10.0
OpenJDK 64-Bit Server VM 21

What may I do so the SDK can actually connect to Couchbase?

Update:

I just created a standalone project to isolate the issue. With this code I do not get any exception:

import com.couchbase.client.java.Cluster;

public class CouchbaseTest {

    public static void main(String[] args) {
        System.out.println("Hello World!");
        Cluster cluster = Cluster.connect("localhost", "user", "password");
    }
}

So my problem must be related to the runtime environment Wildfly 29.0.1.Final. It's full command line is

"C:\Program Files\Microsoft\jdk-21.0.1.12-hotspot\\bin\java"  -Dprogram.name=standalone.bat -Xms64M -Xmx512M -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true  --add-exports=java.desktop/sun.awt=ALL-UNNAMED --add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED --add-exports=java.naming/com.sun.jndi.url.ldap=ALL-UNNAMED --add-exports=java.naming/com.sun.jndi.url.ldaps=ALL-UNNAMED --add-exports=jdk.naming.dns/com.sun.jndi.dns=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.security=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.management/javax.management=ALL-UNNAMED --add-opens=java.naming/javax.naming=ALL-UNNAMED -Djava.security.manager=allow --add-opens jdk.unsupported/sun.misc=deployment.myproject.war --add-opens jdk.unsupported/sun.misc=ALL-UNNAMED    "-Dorg.jboss.boot.log.file=C:\Users\queeg\wildfly-29.0.1.Final\standalone\log\server.log"    "-Dlogging.configuration=file:C:\Users\queeg\wildfly-29.0.1.Final\standalone\configuration/logging.properties"       -jar "C:\Users\queeg\wildfly-29.0.1.Final\jboss-modules.jar"              -mp "C:\Users\queeg\wildfly-29.0.1.Final\modules"       org.jboss.as.standalone       "-Djboss.home.dir=C:\Users\queeg\wildfly-29.0.1.Final"       
0

There are 0 best solutions below