春風(fēng)博客

          春天里,百花香...

          導(dǎo)航

          <2007年11月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          統(tǒng)計(jì)

          公告

          MAIL: junglesong@gmail.com
          MSN: junglesong_5@hotmail.com

          Locations of visitors to this page

          常用鏈接

          留言簿(11)

          隨筆分類(224)

          隨筆檔案(126)

          個(gè)人軟件下載

          我的其它博客

          我的鄰居們

          最新隨筆

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          在Weblogic8上注冊(cè)并啟動(dòng)RMI程序.

          1.做兩個(gè)類Ruler和RulerImpl.
          import java.rmi.Remote;

          public interface Ruler extends Remote {
              
          public String getLength(String str) throws java.rmi.RemoteException;
          }

          import java.rmi.RemoteException;
          import java.rmi.server.UnicastRemoteObject;

          import javax.naming.Context;
          import javax.naming.InitialContext;

          public class RulerImpl extends UnicastRemoteObject implements Ruler {
              
          public RulerImpl() throws RemoteException{
                  
          super();
              }


              
          public String getLength(String str) throws java.rmi.RemoteException {
                           
          // 這里用Sb是因?yàn)閣eblogic的1.4的jdk不認(rèn)StringBuilder
                  StringBuffer sb=new StringBuffer();
                  sb.append(
          "String:");
                  sb.append(str);
                  sb.append(
          "'s length=");
                  sb.append(str.length());
                  
                  
          return sb.toString();
              }

              
              
          public static void main(String[] args){
                  
          try{
                      RulerImpl rulerImpl
          =new RulerImpl();
                      
                      Context ctx
          =new InitialContext();
                      ctx.bind(
          "StringRuler", rulerImpl);
                  }

                  
          catch(Exception ex){
                      ex.printStackTrace();
                  }

              }

          }

          2.用rmic編譯Ruler.class和RulerImpl.class 以生成樁類RulerImpl_Stub.class.
          c:>C:\jdk1.5.0_09\bin\rmic RulerImpl.

          3.將生成的RulerImpl_Stub.class以及原有的Ruler.class和RulerImpl.class拷貝到服務(wù)器的目標(biāo)域中,本人機(jī)器上的是C:\bea\user_projects\domains\mydomain

          4.通過(guò)http://localhost:7001/console 進(jìn)入Weblogic控制臺(tái),并按 yourdomain->Deployment->Startup&Shutdown->Configure a New Startup Class 注冊(cè)啟動(dòng)類.完畢后結(jié)果如下圖:


          5.重新啟動(dòng)Server(Start Server)

          6.通過(guò)客戶端測(cè)試一下:
          import java.util.Hashtable;

          import javax.naming.Context;
          import javax.naming.InitialContext;

          public class RulerClient{
              
          public static void main(String[] args) throws Exception{
                  Hashtable env
          =new Hashtable();
                  env.put(Context.INITIAL_CONTEXT_FACTORY, 
          "weblogic.jndi.WLInitialContextFactory");
                  env.put(Context.PROVIDER_URL,
          "t3://localhost:7001");
                  
                  InitialContext ctx
          =new InitialContext(env);
                  
                  Object o
          =ctx.lookup("StringRuler");
                  Ruler ruler
          =(Ruler)o;
                  System.out.println(ruler.getLength(
          "123"));
              }

          }

          測(cè)試結(jié)果為:
          String:123's length=3

          代碼下載(rmic 目錄中包括三個(gè)已生成類):
          http://www.aygfsteel.com/Files/sitinspring/RmiExample20071106220750.rar

          posted on 2007-11-06 22:22 sitinspring 閱讀(300) 評(píng)論(0)  編輯  收藏 所屬分類: Java基礎(chǔ)

          sitinspring(http://www.aygfsteel.com)原創(chuàng),轉(zhuǎn)載請(qǐng)注明出處.
          主站蜘蛛池模板: 祁连县| 铁力市| 郑州市| 荥经县| 盱眙县| 隆林| 凭祥市| 中卫市| 湖口县| 甘孜县| 丹棱县| 广宗县| 大石桥市| 鲁山县| 安远县| 黄浦区| 辽阳市| 元朗区| 静宁县| 永登县| 衡阳县| 辉县市| 吴旗县| 岑溪市| 盖州市| 兴宁市| 梨树县| 六枝特区| 东宁县| 澄迈县| 通化市| 蒲江县| 沽源县| 绍兴市| 鄢陵县| 铜陵市| 郓城县| 大埔县| 甘谷县| 古蔺县| 平乐县|