2013-10-09 15 views
0

首先这是我在StackOverflow上的第一个问题,我是德国公司的实习生,所以我的英语有点破,我的知识可能有限。远程连接到Jboss应用程序服务器 - NamingIOException导致ClassNotFound

我尝试远程连接到Jboss 6.1.0 eap。 我使用Eclipse作为IDE的EJB和EAR,但我运行Jboss的形式CMD

我的EJB3定义的样子说:

package de.jack; 

import javax.ejb.Remote; 

@Remote 
public interface TestServiceRemote { 
    public void sayRemote(); 

} 

package de.jack; 

import javax.ejb.Stateless; 

/** 
* Session Bean implementation class TestService 
*/ 
@Stateless 
public class TestService implements TestServiceRemote { 

    public TestService() { } 

    public void sayRemote() { 
     System.out.println("\n\nHello"); 
    } 
} 

gernerating .ear文件后,我在他们部署JBoss应用服务器和所有工作正常 我可以在浏览器中查看它们在本地主机:9990,并检查它们被部署

现在到了我失败部分 - 客户端:

public static void main(String argv[]){ 

     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, "jack"); 
     props.put(Context.SECURITY_CREDENTIALS, "katze"); 
     props.put("jboss.naming.client.ejb.context", true); 
     // create a context passing these properties 
     InitialContext context; 
     Object test = null; 
     try { 
      context = new InitialContext(props); 
     } catch (NamingException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      return; 
     } 

     try { 
      test = 
       context.lookup("ConnectorBean/TestService!de.jack.TestServiceRemote"); 
     } catch (NamingException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      return; 
     } 

上运行我得到异常:

org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is java.io.IOException: java.lang.ClassNotFoundException: de.jack.TestServiceRemote] 
    at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:49) 
    at org.jboss.naming.remote.protocol.v1.Protocol$1.execute(Protocol.java:104) 
    at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:95) 
    at org.jboss.naming.remote.client.HaRemoteNamingStore$1.operation(HaRemoteNamingStore.java:245) 
... 

我不知道究竟我做错了 一个原因可能是我没有对maschine管理员权限或我混淆了客户端上的性能

对不起,我的英语不好,我非常感谢任何帮助!

回答

0
  1. 修改TestService的类

    @Stateless 
    @Remote(TestServiceRemote.class) 
    public class TestService implements TestServiceRemote { 
    
        public TestService() { } 
    
        public void sayRemote() { 
         System.out.println("\n\nHello"); 
        } 
    } 
    
  2. 确保远程客户端具有TestServiceRemote.class

  3. 变化查找JNDI名称

    的参考
    // The app name is the application name of the deployed EJBs. This is typically the ear name 
    // without the .ear suffix. However, the application name could be overridden in the application.xml of the 
    // EJB deployment on the server. 
    // Since we haven't deployed the application as a .ear, the app name for us will be an empty string 
    final String appName = ""; 
    // This is the module name of the deployed EJBs on the server. This is typically the jar name of the 
    // EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml 
    // In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is 
    // jboss-as-ejb-remote-app 
    final String moduleName = "jboss-as-ejb-remote-app"; 
    // AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for 
    // our EJB deployment, so this is an empty string 
    final String distinctName = ""; 
    // The EJB name which by default is the simple class name of the bean implementation class 
    final String beanName = TestService.class.getSimpleName(); 
    // the remote view fully qualified class name 
    final String viewClassName = TestServiceRemote.class.getName(); 
    
    String jndiName= "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName; 
    
    TestServiceRemote service = (TestServiceRemote)context.lookup(jndiName); 
    

详情请reffer:https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

+0

谢谢!这帮助了很多 – Jack