【问题标题】:ClassNotFount exception while creating MarkLogic client in Java WebService在 Java WebService 中创建 MarkLogic 客户端时出现 ClassNotFount 异常
【发布时间】:2017-06-29 17:19:45
【问题描述】:

我使用 wsdl 文件生成 Java 类,但我无法在端点中创建 MarkLogic 客户端(它会引发 NoClassFound 异常)。

端点代码:

/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package yu.ac.ns.ftn.informatika.ws.hello;

import java.util.logging.Logger;

import yu.ac.ns.ftn.informatika.ws.hello.types.RequestMissType;

import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClientFactory.Authentication;

/**
 * This class was generated by Apache CXF 2.1.3
 * Fri Jan 23 09:13:16 CET 2009
 * Generated source version: 2.1.3
 * 
 */
@javax.ejb.Stateless
@javax.jws.WebService(
     serviceName = "HelloDocumentService",
     portName = "HelloDocumentPort",
     targetNamespace =   "http://informatika.ftn.ns.ac.yu/ws/hello",
     endpointInterface = "yu.ac.ns.ftn.informatika.ws.hello.HelloDocument")

public class HelloDocumentImpl implements HelloDocument {

private static final Logger LOG = 
Logger.getLogger(HelloDocumentImpl.class.getName());

/* (non-Javadoc)
 * @see 
yu.ac.ns.ftn.informatika.ws.hello.HelloDocument#sayHelloMiss
(yu.ac.ns.ftn.informatika.ws.hello.types.RequestMissType  requestMiss )*
 */


public java.lang.String sayHelloMiss(RequestMissType requestMiss) { 
    LOG.info("Executing operation sayHelloMiss");
    System.out.println(requestMiss);

    DatabaseClient client = 
      DatabaseClientFactory.newClient(
          "localhost", 8000,
          new DatabaseClientFactory.DigestAuthContext("user1", "user1"));
    System.out.println(client);



    return "Hello miss " + requestMiss.getFirstName() + " " + requestMiss.getLastName();
}

}

客户端代码:

package yu.ac.ns.ftn.informatika.ws.client;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import yu.ac.ns.ftn.informatika.ws.hello.HelloDocument;
import yu.ac.ns.ftn.informatika.ws.hello.HelloDocumentService;
import yu.ac.ns.ftn.informatika.ws.hello.types.RequestMissType;

public class HelloClient {

    public void testIt1() {

        try {
            URL wsdlLocation = new URL("http://localhost:8080/vezbe-wsdl-ws/services/HelloDocument?wsdl");
            QName serviceName = new QName("http://informatika.ftn.ns.ac.yu/ws/hello", "HelloDocumentService");
            QName portName = new QName("http://informatika.ftn.ns.ac.yu/ws/hello", "HelloDocumentPort");

            Service service = Service.create(wsdlLocation, serviceName);

            HelloDocument hello = service.getPort(portName, HelloDocument.class); 

            RequestMissType request = new RequestMissType();
            request.setFirstName("Dijana");
            request.setLastName("Ninkovic");

            String response = hello.sayHelloMiss(request);
            System.out.println("Response from WS: " + response);

        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        HelloClient client = new HelloClient();
        client.testIt1();
    }

}

如果我删除用于创建 MarkLogic 客户端的代码,一切正常。

Apache tomee 异常:

org.apache.catalina.LifecycleException: Failed to start component 
[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/vezbe-wsdl-ws]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
 Caused by: java.lang.NoClassDefFoundError: com/marklogic/client/DatabaseClientFactory$SecurityContext
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetPublicMethods(Unknown Source)
    at java.lang.Class.getMethods(Unknown Source)
    at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.processApplicationExceptions(AnnotationDeployer.java:2657)
    at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:2176)
    at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:1662)
    at org.apache.openejb.config.AnnotationDeployer.deploy(AnnotationDeployer.java:335)
    at org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:363)
    at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:850)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:791)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:746)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:118)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more
Caused by: java.lang.ClassNotFoundException: com.marklogic.client.DatabaseClientFactory$SecurityContext
    at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:114)
    at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:66)
    ... 27 more
Caused by: java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
    at java.io.BufferedInputStream.fill(Unknown Source)
    at java.io.BufferedInputStream.read1(Unknown Source)
    at java.io.BufferedInputStream.read(Unknown Source)
    at java.io.FilterInputStream.read(Unknown Source)
    at org.apache.openejb.loader.IO.copy(IO.java:279)
    at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:111)
    ... 28 more

【问题讨论】:

  • 类路径上有两个版本的 Java 客户端 api jar 吗?我问是因为 DatabaseClientFactory$SecurityContext 是 4.0.1 版中的新内容,所以类路径上可能有 3.0.x 可能会导致这种情况。

标签: java web-services soap marklogic


【解决方案1】:

您在部署应用程序时似乎缺少一些 jar。 请确保您已设置好 build.xml 配置,以便它部署您需要的所有 marklogic jar。

<target name="war" depends="compile">
    <delete file="${war.name}"/>
    <war warfile="${dist.dir}/${war.name}" webxml="${webinf.dir}/web.xml">
        <classes dir="${bin.dir}">
            <exclude name="**/client/*.class"/>
            <include name="**/*.class"/>
        </classes>
        <lib dir="${lib.dir}">
            <include name="*.jar"/>
        </lib>
        <webinf dir="${webinf.dir}">
            <include name="wsdl/**"/>
            <include name="cxf-servlet.xml"/>
        </webinf>
    </war>
</target>

祝你好运!

【讨论】:

    猜你喜欢
    • 2013-12-15
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多