在这里,我只介绍操作过程。
一、建立一个工程(project)
file ---> new project
project name 为:helloworld
选择一个该项目的根目录,root path,例如:e:/ejbproject
finish。
二、建立一个ejb gruop
file ---> new ---> enterprise ---> empty ejb group
输入名字:name为:helloworld
ok
三、建立beans
file ---> new ---> enterprise ---> enterprise javabean
next,将发现package中已经有了:helloworld
在class name中输入:helloworldbean
next --->finish
用鼠标双击左边的helloworldbean.java,在
public void setsessioncontext(sessioncontext context) {
sessioncontext = context;
}
后加入一个事件(商业逻辑):
public string gethelloworld(){
return "hello world!";
}
save all,然后ctrl+f9,make,应该是0个错误,0个警告。
四、远程接口的处理
还是在该界面,helloworldbean.java的代码下有一个“bean”,点bean然后methods,将复选框java.lang.string gethelloworld()选上。
五、配置描述(deployment descriptor)
双击“helloworld.ejbgrp”,在下面展开“helloworldbean”
点“container transaction”后,在右边点“add”
interface下是“*”,method下也是“*”,transaction attribute下,选择“required”
save all后,点“verify”进行效验,应该是没有错误的。最后ctrl+f9“make”。
到这里,服务端已经设置好了。
六、用client去测试
file ---> new ---> enterprise ---> ejb test client
发现enterprise javabean中是:helloworldbean
package中是:helloworld
在class中输入类名,比如:helloworldclient
在左边,点“helloworldclient.java”在代码中,有一个try...catch块,在try中的最后面加上下面代码,去调用serve端:
七、配置
鼠标右键点helloworldhome.java
properties --->build --->visibroker
将generate iiop勾上
ok
save all
ctrl+f9 "make"
八、运行
启动visibroker smart agent,方法是:运行visibroker的bin目录下的:osagent.exe文件。(也可以利用jb4的菜单配置工具,将smart agent加到jb4的菜单下,直接从菜单启动)
f9“run”启动container------这个过程也许要花点时间哦。
右键helloworldclient.java点“run”将显示“hello world!”。
如果你看到了,说明已经成功了,否则是哪个步骤不小心,再仔细看吧。
闽公网安备 35060202000074号