• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RMI HELP -- URGENT

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to bet it's an issue with rmiregistry. A common mistake we all make playing with RMI is forgetting to make the stub's interface directly available to rmiregistry. Without that, it cannot properly load the stub.
In my experience, this always manifests itself as a "stub not found" error. Make sure the registry can see the interface behind the stub, and I'm thinking you'll be ok.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
What's wrong? Where are you going? Stop! Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic