一个很简单的rmi的例子,可是却出错!急!
一个core java 2书上的最简单的例子。
Product.java:
import java.rmi.*;
/**
The interface for remote product objects.
*/
public interface Product extends Remote
{
/**
Gets the description of this product.
@return the product description
*/
String getDescription() throws RemoteException;
}
ProductClient.java
import java.rmi.*;
import java.rmi.server.*;
/**
This program demonstrates how to call a remote method
on two objects that are located through the naming service.
*/
public class ProductClient
{
public static void main(String[] args)
{
System.setProperty("java.security.policy", "client.policy");
System.setSecurityManager(new RMISecurityManager());
String url = "rmi://localhost/";
// change to "rmi://yourserver.com/"
// when server runs on remote machine
// yourserver.com
try
{
Product c1 = (Product)Naming.lookup(url + "toaster");
Product c2 = (Product)Naming.lookup(url + "microwave");
System.out.println(c1.getDescription());
System.out.println(c2.getDescription());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
ProductImpl.java:
import java.rmi.*;
import java.rmi.server.*;
/**
This is the implementation class for the remote product
objects.
*/
public class ProductImpl
extends UnicastRemoteObject
implements Product
{
/**
Constructs a product implementation
@param n the product name
*/
public ProductImpl(String n) throws RemoteException
{
name = n;
}
public String getDescription() throws RemoteException
{
return "I am a " + name + ". Buy me!";
}
private String name;
}
ProductServer.java
import java.rmi.*;
import java.rmi.server.*;
/** This server program instantiates two remote objects,
6. registers them with the naming service, and waits for
7. clients to invoke methods on the remote objects.
8. */
public class ProductServer
{
public static void main(String args[])
{
try
{
System.out.println
("Constructing server implementations...");
ProductImpl p1
= new ProductImpl("Blackwell Toaster");
ProductImpl p2
= new ProductImpl("ZapXpress Microwave Oven");
System.out.println
("Binding server implementations to registry...");
Naming.rebind("toaster", p1);
Naming.rebind("microwave", p2);
System.out.println
("Waiting for invocations from clients...");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
按照书上的步骤,编译都可以通过
但是到第2步rmic -v1.2 ProductImpl
却出错:error: Class ProductImpl not found.
我之前还实现过,但是不知道为什么?中间动过环境变量。其他的java application程序都可以运行。
谢了!!!
问题点数:50、回复次数:4Top
1 楼jFresH_MaN(十一月的萧邦-夜曲)回复于 2004-12-04 17:23:48 得分 50
classpath里面的那个点有没有漏掉Top
2 楼liusoft(红薯)回复于 2004-12-04 17:27:43 得分 0
rmic -classpath . ProductImpl
http://www.javayou.comTop
3 楼liuchang2859(liuchang)回复于 2004-12-04 18:02:36 得分 0
什么点?
后面的说的是什么意思?谢Top
4 楼liuchang2859(liuchang)回复于 2004-12-04 18:08:52 得分 0
classpath里应该是什么
我现在是:D:\jakarta-tomcat-5.0.16\common\lib\servlet-api.jar;
应该改成什么?
Top




