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!!!!!!!!