天天看點

java遠端接口調用_java 遠端方法調用

import java.rmi.Naming;

import java.rmi.RemoteException;

import java.rmi.server.UnicastRemoteObject;

import com.XXX.RemoteInterface.MyRemote;

@SuppressWarnings("serial")

public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote{

public String sayHello(int year) throws RemoteException {

return "I invoking this Method names sayHello() in "+year;

}

//此處為空的構造方法

public MyRemoteImpl() throws RemoteException { }

public static void main(String[] args){

try {

MyRemote service = new MyRemoteImpl();

Naming.rebind("/MyRemote/RemoteHello", service);

} catch (Exception e) {

e.printStackTrace();

}

}

}