Java 远程连接到Jboss应用程序服务器-ClassNotFound导致的NamingIOException
首先,这是我关于StackOverflow的第一个问题,我是德国一家公司的实习生,所以我的英语有点不好,我的知识可能有限 我尝试远程连接到Jboss 6.1.0 eap。 我使用Eclipse作为EJB和EAR的IDE,但我运行Jboss表单cmd 我的ejb3定义如下所示:Java 远程连接到Jboss应用程序服务器-ClassNotFound导致的NamingIOException,java,eclipse,jboss,ejb-3.0,Java,Eclipse,Jboss,Ejb 3.0,首先,这是我关于StackOverflow的第一个问题,我是德国一家公司的实习生,所以我的英语有点不好,我的知识可能有限 我尝试远程连接到Jboss 6.1.0 eap。 我使用Eclipse作为EJB和EAR的IDE,但我运行Jboss表单cmd 我的ejb3定义如下所示: package de.jack; import javax.ejb.Remote; @Remote public interface TestServiceRemote { public void sayRem
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");
}
}
生成.ear文件后,我将它们部署到JBoss AS中,所有这些都可以正常工作
我可以在浏览器中的localhost: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)
...
我不确定我到底做错了什么
一个原因可能是我没有对主机的管理权限,或者我混淆了客户端的属性
对不起,我的英语不好,我非常感谢任何帮助 服务器日志应该为bean显示正确的全局JNDI名称。它应该类似于foo/EJB-NAME/remote。然后您需要在context.lookup(“ConnectorBean/TestService!de.jack.TestServiceRemote”)中更改它 请查收-
@Stateless
@Remote(TestServiceRemote.class)
public class TestService implements TestServiceRemote {
public TestService() { }
public void sayRemote() {
System.out.println("\n\nHello");
}
}
// 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);
详情请参考:谢谢!!这帮了大忙