• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    WebLogic的研究之-開發、部署EJB(1)

    發布: 2007-6-10 17:46 | 作者: seanhe | 來源: jspcn | 查看: 23次 | 進入軟件測試論壇討論

    領測軟件測試網

     

     

     

     

     

     

     

     

    這里不會討論EJB的概念,只討論如何編寫一個簡單EJB,部署EJB,Weblogic與JBuilder的整合,本文先把介紹僅用文本編輯器編寫一個最簡單的EJB所需要的一切,以讓大家一覽EJB的概貌,然后才介紹如何把Weblogic與JBuilder整合起來,使用JBuilder開發Weblogic的EJB,我相信這樣會得到很好的學習效果,因為這是我學習的路徑,當然我會把我遇到的問題告訴大家,以免大家走彎路。

    下面是一個最簡單的EJB所需要的代碼及XML說明,手工制作EJB的JAR包比較麻煩,在WIN2000下,我仿照例子制作了一個 build.cmd 批處理文件

    weblogic-ejb-jar.xml
    &lt ?xml version="1.0"? &gt

    &lt !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' &gt

    &lt weblogic-ejb-jar &gt
    &lt weblogic-enterprise-bean &gt
    &lt ejb-name &gtHelloWorldBean&lt /ejb-name &gt
    &lt caching-descriptor &gt
    &lt max-beans-in-free-pool &gt100&lt /max-beans-in-free-pool &gt
    &lt /caching-descriptor &gt
    &lt jndi-name &gthello.HelloWorld&lt /jndi-name &gt
    &lt /weblogic-enterprise-bean &gt
    &lt /weblogic-ejb-jar


    --------------------------------------------------------------------------------
    ejb-jar.xml
    &lt ?xml version="1.0" encoding="GBK"? &gt
    &lt !DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd' &gt

    &lt ejb-jar &gt
    &lt enterprise-beans &gt
    &lt session &gt
    &lt ejb-name &gtHelloWorldBean&lt /ejb-name &gt
    &lt home &gthello.HelloWorldHome&lt /home &gt
    &lt remote &gthello.HelloWorld&lt /remote &gt
    &lt ejb-class &gthello.HelloWorldBean&lt /ejb-class &gt
    &lt session-type &gtStateless&lt /session-type &gt
    &lt transaction-type &gtContainer&lt /transaction-type &gt
    &lt /session &gt
    &lt /enterprise-beans &gt
    &lt assembly-descriptor &gt
    &lt container-transaction &gt
    &lt method &gt
    &lt ejb-name &gtHelloWorldBean&lt /ejb-name &gt
    &lt method-name &gt*&lt /method-name &gt
    &lt /method &gt
    &lt trans-attribute &gtRequired&lt /trans-attribute &gt
    &lt /container-transaction &gt
    &lt /assembly-descriptor &gt
    &lt /ejb-jar &gt

     

    --------------------------------------------------------------------------------
    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 getHelloWorld()");
    startTime = System.currentTimeMillis();
    }

    try {
    returnValue = helloWorld.getHelloWorld();
    if (logging) {
    long endTime = System.currentTimeMillis();
    log("Succeeded: getHelloWorld()");
    log("Execution time: " + (endTime - startTime) + " ms.");
    }
    }
    catch(Exception e) {
    if (logging) {
    log("Failed: getHelloWorld()");
    }
    e.printStackTrace();
    }

    if (logging) {
    log("Return value from getHelloWorld(): " + returnValue + ".");
    }
    return returnValue;
    }

    //----------------------------------------------------------------------------
    // Utility Methods
    //----------------------------------------------------------------------------

    private void log(String message) {
    if (message.length()  &gt MAX_OUTPUT_LINE_LENGTH) {
    System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
    }
    else {
    System.out.println("-- " + message);
    }
    }
    /**Main method*/

    public static void main(String[] args) {
    HelloWorldBeanClient1 client = new HelloWorldBeanClient1();
    // Use the client object to call one of the Home interface wrappers
    // above, to create a Remote interface reference to the bean.
    // If the return value is of the Remote interface type, you can use it
    // to access the remote interface methods. You can also just use the
    // client object to call the Remote interface wrappers.
    }
    }

     

    --------------------------------------------------------------------------------

    build.cmd

    if "" == "%JAVA_HOME%" set JAVA_HOME=java
    if "" == "%WL_HOME%" set WL_HOME=weblogic
    set MYSERVER=%WL_HOME%myserver
    set MYCLASSPATH=%JAVA_HOME%libclasses.zip;%WL_HOME%classes;%WL_HOME%libweblogicaux.jar;%MYSERVER%clientclasses

    @REM Create the build directory, and copy the deployment descriptors into it
    mkdir build buildMETA-INF
    copy *.xml buildMETA-INF

    @REM Compile ejb classes into the build directory (jar preparation)
    javac -d build -classpath %MYCLASSPATH% HelloWorld.java HelloWorldHome.java HelloWorldBean.java

    @REM Make a standard ejb jar file, including XML deployment descriptors
    cd build
    jar cv0f std_ejb_HelloWorld.jar META-INF hello
    cd ..

    @REM Run ejbc to create the deployable jar file
    java -classpath %MYCLASSPATH% -Dweblogic.home=%WL_HOME% weblogic.ejbc -compiler javac buildstd_ejb_HelloWorld.jar %MYSERVER%ejb_Hello.jar

    @REM Compile ejb interfaces & client app into the clientclasses directory
    javac -d %MYSERVER%clientclasses -classpath %MYCLASSPATH% HelloWorld.java HelloWorldHome.java HelloWorldBeanClient1.java





    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備2023014753號-2
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>