春风博客

春天里,百花香...

导航

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

统计

公告

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

Locations of visitors to this page

常用链接

留言簿(11)

随笔分类(224)

随笔档案(126)

个人软件下载

我的其它博客

我的邻居们

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

在Weblogic8上注册并启动RMI程序.

1.做两个类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不认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拷贝到服务器的目标域中,本人机器上的是C:\bea\user_projects\domains\mydomain

4.通过http://localhost:7001/console 进入Weblogic控制台,并按 yourdomain->Deployment->Startup&Shutdown->Configure a New Startup Class 注册启动类.完毕后结果如下图:


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"));
    }

}

测试结果为:
String:123's length=3

代码下载(rmic 目录中包括三个已生成类):
http://www.blogjava.net/Files/sitinspring/RmiExample20071106220750.rar

posted on 2007-11-06 22:22 sitinspring 阅读(294) 评论(0)  编辑  收藏 所属分类: Java基础


只有注册用户登录后才能发表评论。


网站导航:
 
sitinspring(http://www.blogjava.net)原创,转载请注明出处.