aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI HELP -- URGENT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI HELP -- URGENT" Watch "RMI HELP -- URGENT" New topic
Author

RMI HELP -- URGENT

christy smile
Ranch Hand

Joined: Oct 15, 2001
Posts: 101
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

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

What about setting your codebase? And is this a Developer Certification Question? You might want to try the RMI forum.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

The code works fine on my computer...
Try to use the java compiler rmic to make the stub first.
e.g. rmic -v1.2 NextNumberImpl
/ Ren´┐Ż
[This message has been edited by Rene Larsen (edited December 06, 2001).]


Regards, Rene Larsen
Dropbox Invite
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: RMI HELP -- URGENT