在这里,我只介绍操作过程。 一、建立一个工程(project) File ---> New Project 二、建立一个EJB Gruop File ---> New ---> Enterprise ---> Empty EJB Group 三、建立beans File ---> New ---> Enterprise ---> Enterprise JavaBean 用鼠标双击左边的HelloWorldBean.java,在 后加入一个事件(商业逻辑): public String getHelloWorld(){ 四、远程接口的处理 还是在该界面,HelloWorldBean.java的代码下有一个“Bean”,点Bean然后Methods,将复选框java.lang.String getHelloWorld()选上。 五、配置描述(Deployment Descriptor) 双击“HelloWorld.ejbgrp”,在下面展开“HelloWorldBean” 点“Container Transaction”后,在右边点“Add” Save all后,点“Verify”进行效验,应该是没有错误的。最后Ctrl+F9“make”。 到这里,服务端已经设置好了。 六、用Client去测试 File ---> New ---> Enterprise ---> EJB Test Client 在左边,点“HelloWorldClient.java”在代码中,有一个try...catch块,在try中的最后面加上下面代码,去调用Serve端: 七、配置 鼠标右键点HelloWorldHome.java Properties --->Build --->VisiBroker 八、运行 启动VisiBroker Smart Agent,方法是:运行visibroker的bin目录下的:osagent.exe文件。(也可以利用JB4的菜单配置工具,将Smart Agent加到JB4的菜单下,直接从菜单启动) F9“Run”启动Container------这个过程也许要花点时间哦。 右键HelloWorldClient.java点“Run”将显示“Hello World!”。 如果你看到了,说明已经成功了,否则是哪个步骤不小心,再仔细看吧。
Project name 为:HelloWorld
选择一个该项目的根目录,Root path,例如:E:\ejbproject
Finish。
输入名字:Name为:HelloWorld
OK
Next,将发现Package中已经有了:helloworld
在Class name中输入:HelloWorldBean
Next --->Finish
public void setSessionContext(SessionContext context) {
sessionContext = context;
}
return "Hello World!";
}
Save All,然后Ctrl+F9,make,应该是0个错误,0个警告。
Interface下是“*”,Method下也是“*”,Transaction attribute下,选择“Required”
发现Enterprise JavaBean中是:HelloWorldBean
Package中是:helloworld
在Class中输入类名,比如:HelloWorldClient
将Generate IIOP勾上
OK
Save All
Ctrl+F9 "make"