Hi, Ranchers,
I am trying to make a RMI example from Core Jini to work, but I kept on getting acceptions about the _stub file not being found. I believe that I have set up my classpath correctly. The following are the source codes and error that I am getting. Please help if you have any idea. Thank you very much!!!
package corejini.appendixa;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface NextNumber extends Remote
{
public int getNextNumber (int n) throws RemoteException;
}
===========================================================
package corejini.appendixa;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.NotBoundException;
import java.rmi.Naming;
import java.net.MalformedURLException;
public class NextNumberClient
{
public static void main(
String[] args)
{
if (args.length != 1)
{
System.err.println("Usage: NextNumberClient <url>");
System.exit(1);
}
if (System.getSecurityManager() == null)
{
System.setSecurityManager( new RMISecurityManager());
}
Remote r = null;
try
{
//r = Naming.lookup(args[0]);
r = Naming.lookup ("rmi://localhost/nextNumber");
}
catch (RemoteException ex)
{
System.err.println("Couldn't contact registry");
System.err.println("Are you sure you're funning rmiregistry?");
System.exit(1);
}
catch (NotBoundException ex)
{
System.err.println("There is no object bound to " + args[0]);
System.err.println("Are you sure you ran the server?");
System.exit(1);
}
catch (MalformedURLException ex)
{
System.err.println("The string " + args[0] + " is not a valid RMI URL");
System.err.println("Make sure you use a properly-formatted rmi : //URL");
System.exit(1);
}
try
{
if (r instanceof NextNumber)
{
NextNumber nn = (NextNumber) r;
System.out.println("Next number after 1 is : " + nn.getNextNumber(1));
System.out.println("Next number after 2 is : " + nn.getNextNumber(2));
System.out.println("Next number after 3 is : " + nn.getNextNumber(3));
}
else
{
System.err.println("Uh oh, the name " + args[0] + " isn't a NextNumber");
}
}
catch (RemoteException ex)
{
System.err.println("Couldn't start client: " + ex.getMessage());
}
}
}
==========================================================
package corejini.appendixa;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.MalformedURLException;
public class NextNumberImpl extends UnicastRemoteObject implements NextNumber
{
public NextNumberImpl() throws RemoteException
{
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new RMISecurityManager());
}
try
{
System.out.println("Before doing anything...");
InetAddress temp = InetAddress.getLocalHost();
System.out.println("temp is : " +temp);
String host = temp.getHostName();
// String host = "tweedy";
String url = "rmi://" + host+ "/nextNumber";
System.out.println("URL is : " + url);
Naming.rebind(url, this);
System.out.println("Server bound to: " + url);
}
catch (UnknownHostException ex)
{
System.err.println("Couldn't get local host");
System.exit(1);
}
catch (RemoteException ex)
{
System.err.println("Couldn't contact rmiregistry.");
System.err.println("Are you sure you're running rmiregistry?");
ex.printStackTrace();
System.exit(1);
}
catch (MalformedURLException ex)
{
//shouldn't happen
System.exit(1);
}
}
public int getNextNumber(int n)
{
return n + 1;
}
public static void main(String[] args)
{
try
{
NextNumberImpl server = new NextNumberImpl();
}
catch (RemoteException ex)
{
System.err.println("Trouble creating server: " + ex.getMessage());
ex.printStackTrace();
}
}
}
========================================================
The command I used to run it is:
java -Djava.security.policy=e:/private/rmi/rmi/MyProjects/StockRMI/policy.all corejini.appendixa.NextNumberImpl
The policy.all is :
grant {
permission java.security.AllPermission "", "";
};
=====================================================
The exception I am getting is nested Exception, at the bottom, it says that classnotFoundException : corejini.appendixa.NextNumberImpl_stub