如何开发、调试和测试EJB3APP?
1.Install Eclipse + JBOSS IDE 2.0
2.官方的使用JBOSS IDE来开发EJB3 APP的教程还没出来(查看http://www.jboss.com/docs/trailblazer),所以只能用下列步骤
3.创建一个普通的java project,把我自己定义的“ejb library”加入到classpath里,同时把junit 4也添加到classpath
4.打开JBoss Server View:windowàShow ViewàOther..àJBoss Server View
5.在JBoss Server View里create a jboss server,注意:选的server选项如下图:
<!--[if gte vml 1]><v:shape id="图片_x0020_7" o:spid="_x0000_i1027" type="#_x0000_t75" alt="pic1" style='width:325.5pt; height:242.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:/DOCUME~1/bobo/LOCALS~1/Temp/msohtmlclip1/01/clip_image007.jpg" o:title="pic1" /> </v:shape><![endif]-->
创建完之后,JBoss Server View见下图:
<!--[if gte vml 1]><v:shape id="图片_x0020_8" o:spid="_x0000_i1026" type="#_x0000_t75" alt="http://java.chinaitlab.com/UploadFiles_8734/200707/20070712092918236.jpg" style='width:345.75pt;height:224.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:/DOCUME~1/bobo/LOCALS~1/Temp/msohtmlclip1/01/clip_image008.jpg" o:title="20070712092918236" /> </v:shape><![endif]-->
6.如果是要调试的话,则选定server,然后click上图的debug button,如果是运行,则click run button
7.在project root folder下创建好build.xml,它非常重要,用于打包和copy打包的文件到jboss server deploy目录下(build.xml参看自己的ejb3 hello world project)。
8.然后如果要调试的话,就在build.xml的outline view里right click task,然后选择Debug AsàAnt Build(见下图),如果不是调试,则选择Run AsàAnt Build
<!--[if gte vml 1]><v:shape id="图片_x0020_9" o:spid="_x0000_i1025" type="#_x0000_t75" alt="http://java.chinaitlab.com/UploadFiles_8734/200707/20070712092918599.jpg" style='width:237pt;height:186pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:/DOCUME~1/bobo/LOCALS~1/Temp/msohtmlclip1/01/clip_image009.jpg" o:title="20070712092918599" /> </v:shape><![endif]-->
9.进行Junit Test也很容易,但最关键的前提是还是需要先启动jboss server,然后把你的ejb jar发布到jboss里才可以进行junit test,因为ejb的调用离不开ejb container!!那么调用ejb的代码如下:
publicstaticObject getEJB(String jndipath) {
Properties props =newProperties();
props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url","localhost:1099");
props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
InitialContext ctx =newInitialContext(props);
ctx.lookup("HelloWorldBean/remote");