• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

RMI HELP -- URGENT

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • 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

 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about setting your codebase? And is this a Developer Certification Question? You might want to try the RMI forum.
Mark
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic