ClassNotFoundException on Core Java 2 RMI example

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
 
Z

ZelluX

ZelluX said:
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):

Were there any 'package' statements?
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

You have a deployment problem on the server, namely that the Product.class
file is not accessible to it.

No packages decleared, and all files are accessible
 
Z

ZelluX

ZelluX said:
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):

Were there any 'package' statements?
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

You have a deployment problem on the server, namely that the Product.class
file is not accessible to it.

No package statements
And the file permissions have been set to -rw-r--r--
 
Z

ZelluX

For what file, exactly?

I successfully run the server with parameter -
Djava.rmi.server.codebase=file:classDir/
But strangely on windows I can start the server without the parameter.

Thanks a lot~
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top