import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.xrd.ejb3.HelloWorld;
public class EJBClient {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
try{
InitialContext ctx = new InitialContext(props);
HelloWorld hw = (HelloWorld) ctx.lookup("ejb:/helloworld//HelloWorldBean!com.xrd.ejb3.HelloWorld");
System.out.println(hw.sayHello("测试EJB3.0"));
}catch(NamingException e){
System.out.println(e.getMessage());
}
}
}
//jboss-ejb-client.properties 文件
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=admin
remote.connection.default.password=1234
最后这两句的值admin ,1234 是自己的用户名和密码
运行bin目录下的add-user.bat 增加即可
注意这句:ejb:/ 后面的helloworld 是打包后的名称,com.xrd.ejb3.HelloWorld 一定要写全包路径
HelloWorld hw = (HelloWorld) ctx.lookup("ejb:/helloworld//HelloWorldBean!com.xrd.ejb3.HelloWorld");
测试结果:
2012-5-19 1:55:58 org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 1.0.5.Final
2012-5-19 1:55:58 org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.3.GA
2012-5-19 1:55:58 org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.3.GA
2012-5-19 1:55:58 org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.3.GA
2012-5-19 1:55:59 org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: Received server version 1 and marshalling strategies [river]
2012-5-19 1:55:59 org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@105738, receiver=Remoting connection EJB receiver [connection=Remoting connection <18088c0>,channel=jboss.ejb,nodename=hmily]} on channel Channel ID 85653753 (outbound) of Remoting connection 00f11404 to localhost/127.0.0.1:4447
2012-5-19 1:55:59 org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage
WARN: Unsupported message received with header 0xffffffff
测试EJB3.0说:你好,EJB!
JBoss7.11 测试,另外很多人反应JBoss起几分钟后会断掉,不抱错,是因为JBOss没有加用户