So, I'm doing the following:
1. running 'start rmiregistry' from the windows command line (cli). No issues are noted here, however, is there some way of confirming that no errors have occurred?
2. starting another cli session and running 'start java ProductServer'
NOTE: The .class files are compiled successfully within the directory.
Product is an interface not a class (see Product.java below).
|
Code:
|
Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>cd Documents
C:\Users\Administrator\Documents>cd Java Code Snippets
C:\Users\Administrator\Documents\Java Code Snippets>dir
Volume in drive C has no label.
Volume Serial Number is F081-49E8
Directory of C:\Users\Administrator\Documents\Java Code Snippets\Product
05/07/2009 12:54 <DIR> .
05/07/2009 12:54 <DIR> ..
05/07/2009 12:40 219 Product.class
05/07/2009 12:34 286 Product.java
05/07/2009 12:40 632 ProductImpl.class
05/07/2009 12:37 556 ProductImpl.java
05/07/2009 12:55 998 ProductServer.class
05/07/2009 12:54 983 ProductServer.java
6 File(s) 3,674 bytes
2 Dir(s) 138,310,074,368 bytes free
C:\Users\Administrator\Documents\Java Code Snippets\Product>start java ProductSe
rver
C:\Users\Administrator\Documents\Java Code Snippets\Product> |
..and I'm getting the following error:
Constructing server implementations...
Binding server implementations to registry...
javax.naming.CommunicationException [Root exception is java.rmi.ServerException:
RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
java.lang.ClassNotFoundException: Product]
at com.sun.jndi.rmi.registry.RegistryContext.bind(Unk nown Source)
at com.sun.jndi.toolkit.url.GenericURLContext.bind(Un known Source)
at javax.naming.InitialContext.bind(Unknown Source)
at ProductServer.main(ProductServer.java:34)
Caused by: java.rmi.ServerException: RemoteException occurred in server thread;
nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
java.lang.ClassNotFoundException: Product
at sun.rmi.server.UnicastServerRef.oldDispatch(Unicas tServerRef.java:396
)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:1 59)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport. java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:5
35)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(TCPTranspor
t.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport
.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExec
utor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor
.java:908)
at java.lang.Thread.run(Thread.java:619)
at sun.rmi.transport.StreamRemoteCall.exceptionReceiv edFromServer(Unknow
n Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unk nown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
... 4 more
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested ex
ception is:
java.lang.ClassNotFoundException: Product
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknow n Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unicas tServerRef.java:386
)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:1 59)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport. java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:5
35)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(TCPTranspor
t.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport
.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExec
utor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor
.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: Product
at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(L oaderHandler.java:7
11)
at sun.rmi.server.LoaderHandler.loadProxyClass(Loader Handler.java:655)
at sun.rmi.server.LoaderHandler.loadProxyClass(Loader Handler.java:592)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RM IClassLoader.java:6
28)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIC lassLoader.java:294
)
at sun.rmi.server.MarshalInputStream.resolveProxyClas s(MarshalInputStrea
m.java:238)
at java.io.ObjectInputStream.readProxyDesc(ObjectInpu tStream.java:1531)
at java.io.ObjectInputStream.readClassDesc(ObjectInpu tStream.java:1493)
at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1
732)
at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:351)
... 12 more
|
Code:
|
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;
}
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.*;
import javax.naming.*;
/**
This server program instantiates two remote objects,
registers them with the naming service, and waits for
clients to invoke methods on the remote objects.
*/
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();
}
}
} |