4

我正在 JBOSS 7.1.1 服务器中测试 EJB 客户端。EJB 的服务端代码也在同一个虚拟机上。它在运行时抛出“java.lang.ClassNotFoundException: com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote”错误。设置客户端时一切似乎都正确,但我无法弄清楚问题所在。请让我知道我在哪里做错了。

服务器端代码

@Stateless(name = "WhiteBoardService")
@Local(IWhiteBoardService.class)
@Remote(IWhiteBoardServiceRemote.class)
public class WhiteBoardService implements IWhiteBoardService {

    private WhiteBoardPersistenceImpl whiteBoardPersistenceImpl = WhiteBoardPersistenceImpl
            .getInstance();
    private CoursePersistenceImpl coursePersistenceImpl = CoursePersistenceImpl
            .getInstance();

    @Override
    public LongKeyValue[] getWhiteBoardContent(long courseSessionGuid, UserSession userSession) {
        // returns the attachment Guid and the Attachment Title
        return whiteBoardPersistenceImpl.getAttachmentForWhiteBoard(courseSessionGuid, userSession) ;
    }......

本地接口

@Local
public interface IWhiteBoardService {

    public WhiteBoardSessionVO openWhiteBoard(long courseSessionGuid, UserSession userSession);
    public WhiteBoardSessionVO joinWhiteBoard(long courseSessionGuid,UserSession userSession);
    public LongKeyValue[] getWhiteBoardContent(long courseSessionGuid, UserSession userSession);
}

远程接口

public interface IWhiteBoardServiceRemote extends IWhiteBoardService{


}

EJB 已部署

20:42:32,278 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named WhiteBoardService in deployment unit subdeployment "emyed-ejb-1.0.jar" of deployment "emyed-ear.ear" are as follows:

    java:global/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    java:app/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    java:module/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    java:jboss/exported/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    java:global/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardService
    java:app/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardService
    java:module/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardService

客户端类

public class WhiteboardService {

    public static void main(String[] args){

        Context context=null;
           try
             {
                    Properties props = new Properties();
                    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                    props.put(Context.PROVIDER_URL, "remote://localhost:4447");
                    props.put(Context.SECURITY_PRINCIPAL, "ejbremote");
                    props.put(Context.SECURITY_CREDENTIALS, "remote4u");
                    context = new InitialContext(props);
                System.out.println("\n\tGot initial Context: "+context);
             }
           catch (Exception e)
             {
                    e.printStackTrace();
              }

             // Lookup Format will be
             // <app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>

           IWhiteBoardServiceRemote whiteboardService = null;
        try {
            Object obj = context.lookup("java:jboss/exported/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote");
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
             System.out.println("\n\t (\"MiddlewareMagic\") = "+ whiteboardService.getWhiteBoardContent(1, null));

    }

控制台日志

02:13:45,303  INFO xnio:63 - XNIO Version 3.0.3.GA
02:13:45,355  INFO nio:55 - XNIO NIO Implementation Version 3.0.3.GA
02:13:45,469  INFO remoting:70 - JBoss Remoting version 3.2.3.GA

    Got initial Context: javax.naming.InitialContext@5a92668c
javax.naming.NameNotFoundException: jboss/exported/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote -- service jboss.naming.context.java.jboss.exported.jboss.exported.emyed-ear."emyed-ejb-1.0"."WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote"
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Exception in thread "main" java.lang.NoClassDefFoundError: com/zreflect/emyed/ejb/interfaces/IWhiteBoardServiceRemote
    at com.zreflect.emyed.whiteboard.service.WhiteboardService.main(WhiteboardService.java:47)
Caused by: java.lang.ClassNotFoundException: com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 1 more
4

2 回答 2

4

您是否尝试过可移植的 JNDI 名称:

java:global/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote

代替

java:jboss/exported/emyed-ear/emyed-ejb-1.0/WhiteBoardService!com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote

?

于 2013-03-05T11:30:22.687 回答
2

您的堆栈跟踪表明异常是在客户端引发的。这可能是因为您在客户端的类路径中没有com.zreflect.emyed.ejb.interfaces.IWhiteBoardServiceRemote类定义。

您可能需要参考AS7 中的类加载。我将不得不看看您如何打包您的应用程序以提供进一步的帮助。

于 2013-02-27T20:52:54.243 回答