2022年Eclipse开发EJB文档 .pdf
《2022年Eclipse开发EJB文档 .pdf》由会员分享,可在线阅读,更多相关《2022年Eclipse开发EJB文档 .pdf(19页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Eclipse开发 EJB 文档此文档主要介绍了在eclipse IDE 下开发 EJB,着重介绍开发session bean的环境配置,开发过程,打包,部署,应用程序调用,关于entity bean,消息驱动bean 下次再给大家分解. 一、 session bean 环境配置及开发过程1.配置编译环境名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 19 页 - - - - - - - - - 注:由于 EJB2.0 技术相对很早, 所以 jdk,jre 都是 1.4,
2、建议用发布服务器自带的低版本jdk,jre ,这样相对保险一些。二、开发session过程1.建立 EJB 工程名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 19 页 - - - - - - - - - 2.建立一个 Session bean 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 19 页 - - - - - - - - - 代码如下:p
3、ackage com.first.ejb; import java.rmi.RemoteException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; publicclass hello implements SessionBean /*Thesessioncontext*/private SessionContext context; public hello() / TODO Auto-generated constructor stub pub
4、licvoid ejbActivate() throws EJBException, RemoteException / TODO Auto-generated method stub名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 19 页 - - - - - - - - - publicvoid ejbPassivate() throws EJBException, RemoteException / TODO Auto-generated method stub pu
5、blicvoid ejbRemove() throws EJBException, RemoteException / TODO Auto-generated method stub publicvoid setSessionContext(SessionContext newContext) throws EJBException context = newContext; publicvoid replaceWithRealBusinessMethod() throws EJBException / rename and start putting your business logic
6、here public String login() returnhello world!; 3.用eclipse Xdoclet生成相应的 Home接口,远程接口,实现远程接口的bean ,具体操作如下:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 19 页 - - - - - - - - - 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 19
7、 页 - - - - - - - - - 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 19 页 - - - - - - - - - 到此, EJB 自动生成接口已经设置成功。4.运行Xdoclet生成相应的接口,如图名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 19 页 - - - - - - - - - 这时已经生成代码雏形,然后再手写一些代
8、码,把远程调用方法实现,具体代码如下:hello.java 文件package com.first.ejb; import java.rmi.RemoteException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; publicclass hello implements SessionBean /*Thesessioncontext*/private SessionContext context; 名师资料总结 - - -精品资料欢迎下载 - -
9、 - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 19 页 - - - - - - - - - public hello() / TODO Auto-generated constructor stub publicvoid ejbActivate() throws EJBException, RemoteException / TODO Auto-generated method stub publicvoid ejbPassivate() throws EJBException, RemoteException /
10、TODO Auto-generated method stub publicvoid ejbRemove() throws EJBException, RemoteException / TODO Auto-generated method stub publicvoid setSessionContext(SessionContext newContext) throws EJBException context = newContext; publicvoid replaceWithRealBusinessMethod() throws EJBException / rename and
11、start putting your business logic here public String login() returnhello world!; helloSession.java 文件package com.first.ejb; public class helloSession extends com.first.ejb.hello implements javax.ejb.SessionBean public void ejbActivate() throws javax.ejb.EJBException, java.rmi.RemoteException 名师资料总结
12、- - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 19 页 - - - - - - - - - super.ejbActivate(); public void ejbPassivate() throws javax.ejb.EJBException, java.rmi.RemoteException super.ejbPassivate(); public void setSessionContext(javax.ejb.SessionContext ctx) throws java
13、x.ejb.EJBException super.setSessionContext(ctx); public void unsetSessionContext() public void ejbRemove() throws javax.ejb.EJBException, java.rmi.RemoteException super.ejbRemove(); public void ejbCreate() throws javax.ejb.CreateException Hello.java 文件,定义远程接口package com.first.interfaces; import java
14、.rmi.RemoteException; publicinterface hello extends javax.ejb.EJBObject publicvoid replaceWithRealBusinessMethod( ) throws java.rmi.RemoteException; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 19 页 - - - - - - - - - public String login() throws RemoteExcept
15、ion; helloHome.java 文件定义 Home接口package com.first.interfaces; public interface helloHome extends javax.ejb.EJBHome public static final String COMP_NAME=java:comp/env/ejb/hello; public static final String JNDI_NAME=ejb/hello; public com.first.interfaces.hello create() throws javax.ejb.CreateException,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年Eclipse开发EJB文档 2022 Eclipse 开发 EJB 文档
限制150内