如何将文件从服务器导出到客户端-JavaRMI
我是JavaRMI新手,我只是想运行一个“HelloWorld”程序(代码显示在消息末尾) 基本上,我在一台计算机上有一个远程类、一个远程接口和一个服务器类,在另一台计算机上有一个客户端类。 我正在尝试使用客户端从服务器获取“hello”消息。 问题是,如果远程接口和存根不在客户端所在的同一目录中,我就无法编译客户端并使其运行;同时,如果远程接口和存根不在服务器所在的同一目录中,我就无法运行服务器 我使用javac编译了服务器/远程类/接口,然后使用rmic编译器。 “rmic你好” 我想知道我如何才能让它工作,而不必在两台计算机上都有所有的文件(这就是为什么我想让它分发) 提前谢谢 代码: 远程接口:如何将文件从服务器导出到客户端-JavaRMI,java,rmi,Java,Rmi,我是JavaRMI新手,我只是想运行一个“HelloWorld”程序(代码显示在消息末尾) 基本上,我在一台计算机上有一个远程类、一个远程接口和一个服务器类,在另一台计算机上有一个客户端类。 我正在尝试使用客户端从服务器获取“hello”消息。 问题是,如果远程接口和存根不在客户端所在的同一目录中,我就无法编译客户端并使其运行;同时,如果远程接口和存根不在服务器所在的同一目录中,我就无法运行服务器 我使用javac编译了服务器/远程类/接口,然后使用rmic编译器。 “rmic你好” 我想知道我
import java.rmi.*;
//Remote Interface for the "Hello, world!" example.
public interface HelloInterface extends Remote {
public String say() throws RemoteException;
}
远程类:
import java.rmi.*;
import java.rmi.server.*;
public class Hello extends UnicastRemoteObject implements HelloInterface {
private String message;
public Hello (String msg) throws RemoteException {
message = msg;
}
public String say() throws RemoteException {
return message;
}
}
客户:
导入java.rmi.*
public class Client
{
public static void main (String[] argv)
{
try
{
HelloInterface hello= (HelloInterface) Naming.lookup(host); //the string representing the host was modified to be posted here
System.out.println (hello.say());
}
catch (Exception e)
{
System.out.println ("Hello Server exception: " + e);
}
}
}
服务器:
public static void main (String[] argv) {
try {
Naming.rebind ("Hello", new Hello ("Hello, world!"));
System.out.println ("Hello Server is ready.");
} catch (Exception e) {
System.out.println ("Hello Server failed: " + e);
}
}
我的猜测是简单地在两端/任一端创建相同的源 我想知道我怎样才能让它工作,而不必在两台计算机上都有所有的文件 你不能。您必须将所需的类文件分发给客户端 (这就是为什么我想将其分发) 非顺序逻辑