1:新建一个EJB Project
2:创建一个session接口
package com.chen;
import javax.ejb.Remote;
/**
* @author chenguibing
* @date 2014-5-24
*/
@Remote(value=MySessionBean.class)
public interface MySessionBean {
public String say();
}
3:创建一个实现类
package com.chen;
import javax.ejb.Remote;
import javax.ejb.Stateless;
/**
* @author chenguibing
* @date 2014-5-24
*/
@Stateless(mappedName = "MySessionBeanImpl")
public class MySessionBeanImpl implements MySessionBean{
/* (non-Javadoc)
* @see com.chen.MySessionBean#say()
*/
@Override
public String say() {
return "hello chenguibing!!!!!!!!";
}
}
4:创建Test类
package com.chen;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author chenguibing
* @date 2014-5-24
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001"
);
try{
InitialContext ctx = new InitialContext(p);
MySessionBean bean=(MySessionBean)ctx.lookup("MySessionBeanImpl#com.chen.MySessionBean");
String say = bean.say();
System.out.println(say);
}
catch(NamingException e) {
e.printStackTrace();
}
}
}
完后的目录:
5:创建一个wlfullclieng.jar。方法:
a、进入weblogic的lib路径
cd WL_HOME
/server/lib
b、创建新的wlfullclient.jar包
java -jar wljarbuilder.jar
c、将创建的wlfullclient.jar添加到你的应用程序的Build Path下就可以了。
6:用MyEclipse10自动部署Ejb
7:
8:运行Test类
运行结果:hello chenguibing!!!!!!!!