和風(fēng)細(xì)雨

          世上本無難事,心以為難,斯乃真難。茍不存一難之見于心,則運用之術(shù)自出。

          在Weblogic8上注冊并啟動RMI程序.

          .做兩個類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是因為weblogic的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)域中,本人機器上的是C:\bea\user_projects\domains\mydomain

          4.通過http://localhost:7001/console 進入Weblogic控制臺,并按 yourdomain->Deployment->Startup&Shutdown->Configure a New Startup Class 注冊啟動類.完畢后結(jié)果如下圖:


          5.重新啟動Server(Start Server)

          6.通過客戶端測試一下:
          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"));
              }

          }

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

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

          posted on 2008-02-22 11:25 和風(fēng)細(xì)雨 閱讀(230) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 金秀| 通榆县| 深水埗区| 南丹县| 渑池县| 鄱阳县| 保定市| 常宁市| 阳春市| 抚宁县| 清新县| 札达县| 朔州市| 湖北省| 潮安县| 安岳县| 自贡市| 宁强县| 漾濞| 繁峙县| 鄂托克旗| 新民市| 包头市| 云林县| 湟源县| 阿坝县| 云和县| 石林| 荃湾区| 新化县| 饶阳县| 贺州市| 邯郸县| 遵义市| 和龙市| 台中市| 淮南市| 贵定县| 白沙| 霍邱县| 黎平县|