Z
ZelluX
Hi all,
I'm trying out some sample code on Core Java 2 Chapter 5 - Distributed
Objects, but even though the code is identical to that on the book, it
says
javax.naming.CommunicationException [Root exception is
java.rmi.ServerException: RemoteException occurred in server thread;
nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments;
nested exception is:
java.lang.ClassNotFoundException: Product]
....
Code snippets(comments and imports removed):
public interface Product extends Remote {
String getDescription() throws RemoteException;
}
public class ProductClient {
public static void main(String[] args) {
System.setProperty("java.security.policy", "client.policy");
System.setSecurityManager(new RMISecurityManager());
String url = "rmi://localhost/";
try {
Context namingContext = new InitialContext();
Product c1 = (Product) namingContext.lookup(url + "toaster");
Product c2 = (Product) namingContext.lookup(url +
"microwave");
System.out.println(c1.getDescription());
System.out.println(c2.getDescription());
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class ProductImpl extends UnicastRemoteObject implements
Product {
public ProductImpl(String n) throws RemoteException {
name = n;
}
public String getDescription() throws RemoteException {
return "I am a " + name + ". Buy me!";
}
private String name;
}
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...");
Context namingContext = new InitialContext();
namingContext.bind("rmi:toaster", p1);
namingContext.bind("rmi:microwave", p2);
System.out.println("Waiting for invocations from
clients...");
} catch (Exception e) {
e.printStackTrace();
}
}
}
All the files are under /home/abc/Product, and I run the program
following these steps:
cd /home/abc/Product
rmiregistry &
java ProductServer
then the error occurs
Java version: 1.6.0 (so there's no need to run rmic according to the
book)
How to solve the problem? Many thanks
I'm trying out some sample code on Core Java 2 Chapter 5 - Distributed
Objects, but even though the code is identical to that on the book, it
says
javax.naming.CommunicationException [Root exception is
java.rmi.ServerException: RemoteException occurred in server thread;
nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments;
nested exception is:
java.lang.ClassNotFoundException: Product]
....
Code snippets(comments and imports removed):
public interface Product extends Remote {
String getDescription() throws RemoteException;
}
public class ProductClient {
public static void main(String[] args) {
System.setProperty("java.security.policy", "client.policy");
System.setSecurityManager(new RMISecurityManager());
String url = "rmi://localhost/";
try {
Context namingContext = new InitialContext();
Product c1 = (Product) namingContext.lookup(url + "toaster");
Product c2 = (Product) namingContext.lookup(url +
"microwave");
System.out.println(c1.getDescription());
System.out.println(c2.getDescription());
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class ProductImpl extends UnicastRemoteObject implements
Product {
public ProductImpl(String n) throws RemoteException {
name = n;
}
public String getDescription() throws RemoteException {
return "I am a " + name + ". Buy me!";
}
private String name;
}
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...");
Context namingContext = new InitialContext();
namingContext.bind("rmi:toaster", p1);
namingContext.bind("rmi:microwave", p2);
System.out.println("Waiting for invocations from
clients...");
} catch (Exception e) {
e.printStackTrace();
}
}
}
All the files are under /home/abc/Product, and I run the program
following these steps:
cd /home/abc/Product
rmiregistry &
java ProductServer
then the error occurs
Java version: 1.6.0 (so there's no need to run rmic according to the
book)
How to solve the problem? Many thanks