EJB3.1+MyEclipse10+WebLogic10示例

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

發佈了28 篇原創文章 · 獲贊 2 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章