添加属性元数据时出现异常

Exception while adding Properties Metadata

我们正在使用以下代码将 属性元数据 添加到 MarkLogic 中的文档,但我们收到 javax.xml.bind.DatatypeConverter 异常。

DocumentMetadataHandle documentMetadataHandle = new DocumentMetadataHandle();
documentMetadataHandle.getProperties().put("test", "test");
XMLDocumentManager xmldocMgr = client.newXMLDocumentManager();
xmldocMgr.write("/test/sample", metadataHandle, domHandle);

我们使用的是 MarkLogic 10.0.-2.1,Java 客户端 API 版本是 4.1.0

例外是

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
    at com.marklogic.client.impl.ValueConverter.StringToString(ValueConverter.java:575)
    at com.marklogic.client.impl.ValueConverter.convertFromJava(ValueConverter.java:253)
    at com.marklogic.client.impl.ValueConverter.convertFromJava(ValueConverter.java:94)
    at com.marklogic.client.io.DocumentMetadataHandle.sendPropertiesImpl(DocumentMetadataHandle.java:888)
    at com.marklogic.client.io.DocumentMetadataHandle.sendMetadataImpl(DocumentMetadataHandle.java:791)
    at com.marklogic.client.io.DocumentMetadataHandle.write(DocumentMetadataHandle.java:575)
    at com.marklogic.client.impl.StreamingOutputImpl.writeTo(StreamingOutputImpl.java:58)
    at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.java:173)
    at okhttp3.MultipartBody.writeTo(MultipartBody.java:114)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:69)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:43)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at com.burgstaller.okhttp.AuthenticationCacheInterceptor.intercept(AuthenticationCacheInterceptor.java:45)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
    at okhttp3.RealCall.execute(RealCall.java:81)
    at com.marklogic.client.impl.OkHttpServices.sendRequestOnce(OkHttpServices.java:706)
    at com.marklogic.client.impl.OkHttpServices.sendRequestOnce(OkHttpServices.java:701)
    at com.marklogic.client.impl.OkHttpServices.putPostDocumentImpl(OkHttpServices.java:1550)
    at com.marklogic.client.impl.OkHttpServices.putDocument(OkHttpServices.java:1260)
    at com.marklogic.client.impl.DocumentManagerImpl.write(DocumentManagerImpl.java:920)
    at com.marklogic.client.impl.DocumentManagerImpl.write(DocumentManagerImpl.java:758)
    at com.marklogic.client.impl.DocumentManagerImpl.write(DocumentManagerImpl.java:702)
    at com.lock.DemoApplication.createXMLDocument(DemoApplication.java:36)
    at com.lock.DemoApplication.main(DemoApplication.java:64)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 36 more

请帮助我们解决这个问题。

编译使用的是什么Java版本?

Java 的最新版本已将 JAXB(包括数据类型转换器例程)移出核心 Java 库并移至可选的下载库中。

下面是如何使用 Gradle 添加这些依赖项的示例:

https://github.com/marklogic/java-client-api/blob/master/marklogic-client-api/build.gradle#L10-L14

希望对您有所帮助,