网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  weblogic的研究之开发、部署ejb(1)     
  文章作者:未知  文章来源:水木森林  
  查看:135次  录入:管理员--2007-11-17  
 
  weblogic的研究之开发、部署ejb(1)

这里不会讨论ejb的概念,只讨论如何编写一个简单ejb,部署ejb,weblogic与jbuilder的整合,本文先把介绍仅用文本编辑器编写一个最简单的ejb所需要的一切,以让大家一览ejb的概貌,然后才介绍如何把weblogic与jbuilder整合起来,使用jbuilder开发weblogic的ejb,我相信这样会得到很好的学习效果,因为这是我学习的路径,当然我会把我遇到的问题告诉大家,以免大家走弯路。

下面是一个最简单的ejb所需要的代码及xml说明,手工制作ejb的jar包比较麻烦,在win2000下,我仿照例子制作了一个 build.cmd 批处理文件

weblogic-ejb-jar.xml
<?xml version="1.0"?>

<!doctype weblogic-ejb-jar public ´-//bea systems, inc.//dtd weblogic 5.1.0 ejb//en´ ´ ;http://www.bea.com/servers/wls510/dtd/weblogic-ejb-jar.dtd´ ;>

<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>helloworldbean</ejb-name>
<caching-descriptor>
<max-beans-in-free-pool>100</max-beans-in-free-pool>
</caching-descriptor>
<jndi-name>hello.helloworld</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar

--------------------------------------------------------------------------------
ejb-jar.xml
<?xml version="1.0" encoding="gbk"?>
<!doctype ejb-jar public ´-//sun microsystems, inc.//dtd enterprise javabeans 1.1//en´ ´ ;http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd´ ;>

<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>helloworldbean</ejb-name>
<home>hello.helloworldhome</home>
<remote>hello.helloworld</remote>
<ejb-class>hello.helloworldbean</ejb-class>
<session-type>stateless</session-type>
<transaction-type>container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>helloworldbean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

--------------------------------------------------------------------------------
package hello;
import java.rmi.*;
import javax.ejb.*;

public class helloworldbean implements sessionbean {
private sessioncontext sessioncontext;
public void ejbcreate() {
}
public void ejbremove() {
}
public void ejbactivate() {
}
public void ejbpassivate() {
}
public void setsessioncontext(sessioncontext context) {
sessioncontext = context;
}
public string gethelloworld(){
return "hello world!";
}
}
--------------------------------------------------------------------------------
helloworld.java
package hello;
import java.rmi.*;
import javax.ejb.*;

public interface helloworld extends ejbobject {
public java.lang.string gethelloworld() throws remoteexception;
}
--------------------------------------------------------------------------------
helloworldhome.java
package hello;
import java.rmi.*;
import javax.ejb.*;

public interface helloworldhome extends ejbhome {
public helloworld create() throws remoteexception, createexception;
}
--------------------------------------------------------------------------------

helloworldbean.java
package hello;
import java.rmi.*;
import javax.ejb.*;

public class helloworldbean implements sessionbean {
private sessioncontext sessioncontext;
public void ejbcreate() {
}
public void ejbremove() {
}
public void ejbactivate() {
}
public void ejbpassivate() {
}
public void setsessioncontext(sessioncontext context) {
sessioncontext = context;
}
public string gethelloworld(){
return "hello world!";
}
}
--------------------------------------------------------------------------------

helloworldbeanclient1.java
package hello;

import javax.naming.*;
import javax.rmi.portableremoteobject;

public class helloworldbeanclient1 {
private static final string error_null_remote = "remote interface reference is null. it must be created by calling one of the home interface methods first.";
private static final int max_output_line_length = 50;
private boolean logging = true;
private helloworldhome helloworldhome = null;
private helloworld helloworld = null;

/**construct the ejb test client*/
public helloworldbeanclient1() {
long starttime = 0;
if (logging) {
log("initializing bean access.");
starttime = system.currenttimemillis();
}

try {
//get naming context
context ctx = new initialcontext();

//look up jndi name
object ref = ctx.lookup("helloworld");

//cast to home interface
helloworldhome = (helloworldhome) portableremoteobject.narrow(ref, helloworldhome.class);
if (logging) {
long endtime = system.currenttimemillis();
log("succeeded initializing bean access.");
log("execution time: " + (endtime - starttime) + " ms.");
}

helloworld hello=helloworldhome.create();
string str=hello.gethelloworld();
system.out.println(str);
}
catch(exception e) {
if (logging) {
log("failed initializing bean access.");
}
e.printstacktrace();
}
}
//----------------------------------------------------------------------------
// methods that use home interface methods to generate a remote interface reference
//----------------------------------------------------------------------------

public helloworld create() {
long starttime = 0;
if (logging) {
log("calling create()");
starttime = system.currenttimemillis();
}
try {
helloworld = helloworldhome.create();
if (logging) {
long endtime = system.currenttimemillis();
log("succeeded: create()");
log("execution time: " + (endtime - starttime) + " ms.");
}
}
catch(exception e) {
if (logging) {
log("failed: create()");
}
e.printstacktrace();
}

if (logging) {
log("return value from create(): " + helloworld + ".");
}
return helloworld;
}

//----------------------------------------------------------------------------
// methods that use remote interface methods to access data through the bean
//----------------------------------------------------------------------------

public string gethelloworld() {
string returnvalue = "";
if (helloworld == null) {
system.out.println("error in gethelloworld(): " + error_null_remote);
return returnvalue;
}
long starttime = 0;
if (logging) {
log("calling geth
 
 
上一篇: weblogic的结构特点    下一篇: weblogic的研究之开发、部署ejb(2)
  相关文档
hibernate 深入研究之 criteria 11-17
p2p的jxta解决之道 11-17
利用eclipse进行重构(上) 11-17
java 在client/server 中应用 11-16
java类加载的表现形式 11-17
java入门视频教程-第95讲 11-17
从原理上解决tomcat中文问题 11-17
java实例 阴阳历算法 11-17
item 属性 11-16
小心进行 j2ee web services 的测试 11-17
动态编译java程序 11-17
在Java中实现条件编译 04-14
j2me的体系结构 11-17
嵌入式java的应用实例 11-17
java基础:用java实现http文件队列下载 11-16
类的基本概念 11-17
java security notes (6) 11-17
java 有用论 11-17
java异常处理的陋习展播 11-16
java 开发环境的过去、现在和将来 11-16
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
厦门(总部):13616026886 福州:0591-87655121
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息