简体   繁体   中英

Cannot connect to marklogic server using java api

I am quite new in using the java api of marklogic. I am simply trying to establish a connection to it by:

 DatabaseClient client =
              DatabaseClientFactory.newClient("localhost", 8001,
                                              "admin", "password",
                                              Authentication.DIGEST);

The exception I get is:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/core/MultivaluedMap
at com.marklogic.client.DatabaseClientFactory.newClientImpl(DatabaseClientFactory.java:259)
at com.marklogic.client.DatabaseClientFactory.newClient(DatabaseClientFactory.java:253)
at com.marklogic.client.DatabaseClientFactory.newClient(DatabaseClientFactory.java:224)
at test_package.MainClass.main(MainClass.java:14)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.MultivaluedMap
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 4 more

Any idea?

You're missing a library that's needed to make this work. It seems to be part of JSR-311 . Download the jar, and make sure it's on your classpath. If you're using Maven, this post might be of use.

David's point is well taken. The Java API does provide a POM file for automating installation of the dependencies and, if you aren't using Maven, documents the dependencies.

In addition, you can only use the Java API after creating a MarkLogic REST server for the database.

Please see: http://docs.marklogic.com/guide/java/intro#id_69370

Hoping that helps,

Erik Hennum

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM