Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

ClassNotFoundException - Check this out.

843793Jul 19 2004 — edited Sep 30 2005
Hello, I am implementing simple client server RMI application. But I am getting this error when I run my client,
RemoteException
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: CalculatorImpl_Stub (no security manager: RMI class loader disabled)

Here is my server file, CalculatorServer.java
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.util.Properties;

public class CalculatorServer  {

   public CalculatorServer() {
	 try {
       //Create an instance of the Server
	   Calculator c = new CalculatorImpl();
	   Properties p = System.getProperties();
	   System.setProperty("java.security.policy","C:\\Program Files\\eclipse\\security\\rmi.policy");
	   System.setProperty("java.rmi.server.codebase","file:///P:\\Projects\\RMIServer\\bin"); 
	   
	   //Register the security manager if necessary.
	   if (System.getSecurityManager() == null) {
	       System.setSecurityManager(new RMISecurityManager());
	   }	
	   System.out.println("Security manager registered");
	   
	   //Create the registry
	   LocateRegistry.createRegistry(1099);
	   System.out.println("Registry started at 1099");	   
	   
	   //Bind the server into the registry with a given name
	   Naming.rebind("rmi://localhost:1099/CalculatorService", c);
	   System.out.println("Service registered");
	   
	 } catch (Exception e) {
	   System.out.println("Trouble: " + e);
	 }
   }

   public static void main(String args[]) {
	 new CalculatorServer();
   }
}
and here is my client file, CalculatorClient.java
import java.rmi.Naming; 
import java.rmi.RemoteException; 
import java.net.MalformedURLException; 
import java.rmi.NotBoundException;
 
public class CalculatorClient { 
 
	public static void main(String[] args) { 
		try { 
		    System.out.println("Starting client");
			Calculator c = (Calculator)Naming.lookup("rmi://localhost:1099/CalculatorService");
			System.out.println("Got stub from the server");
			System.out.println( c.sub(4, 3) ); 
			System.out.println( c.add(4, 5) ); 
			System.out.println( c.mul(3, 6) ); 
			System.out.println( c.div(9, 3) ); 
		} 
		catch (MalformedURLException murle) { 
			System.out.println(); 
			System.out.println(
			  "MalformedURLException"); 
			System.out.println(murle); 
		} 
		catch (RemoteException re) { 
			System.out.println(); 
			System.out.println(
						"RemoteException"); 
			System.out.println(re); 
		} 
		catch (NotBoundException nbe) { 
			System.out.println(); 
			System.out.println(
					   "NotBoundException"); 
			System.out.println(nbe); 
		} 
		catch (
			java.lang.ArithmeticException
									  ae) { 
			System.out.println(); 
			System.out.println(
			 "java.lang.ArithmeticException"); 
			System.out.println(ae); 
		} 
	} 
} 
when I run this from the same directory I runs perfectly fine but when I have separated client & server files, it gives me this error.
I have already set codebase programatically as well as in Eclipse IDE too. But couldnt get any solution.
Can anybody please advise?
Thanks,
satya008

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 28 2005
Added on Jul 19 2004
13 comments
2,257 views