• 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

UnMarshalException - Nested ClassNotFoundException again

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:
Please help.
I am tring RMI allday today. But still cannot get it run
All of them throw the error below when I run ServerImpl
Trouble: java.rmi.ServerException: Server RemoteException; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
java.lang.ClassNotFoundException: CalculatorImpl_Stub
I am trying the simple code from sun's rmi tutorial.
* I am using j2sdk1.4.0 on window xp.
* All files set in the same directory in ..\Calculator
* cd ..\Calculator
* I use javac *.java compile them
* rmic -v1.2 CalculatorImpl to get CalculatorImpl_stub.class
* start rmiregistry
* java CalculatorServer, the above error display

//************************************
public interface Calculator
extends java.rmi.Remote {
public long add(long a, long b)
throws java.rmi.RemoteException;
public long sub(long a, long b)
throws java.rmi.RemoteException;
public long mul(long a, long b)
throws java.rmi.RemoteException;
public long div(long a, long b)
throws java.rmi.RemoteException;
}
//************************************
public class CalculatorImpl
extends
java.rmi.server.UnicastRemoteObject
implements Calculator {
// Implementations must have an
//explicit constructor
// in order to declare the
//RemoteException exception
public CalculatorImpl()
throws java.rmi.RemoteException {
super();
}
public long add(long a, long b)
throws java.rmi.RemoteException {
return a + b;
}
public long sub(long a, long b)
throws java.rmi.RemoteException {
return a - b;
}
public long mul(long a, long b)
throws java.rmi.RemoteException {
return a * b;
}
public long div(long a, long b)
throws java.rmi.RemoteException {
return a / b;
}
}
//************************************
import java.rmi.Naming;
public class CalculatorServer {
public CalculatorServer() {
try {
Calculator c = new CalculatorImpl();
Naming.rebind("rmi://localhost:1099/CalculatorService", c);
} catch (Exception e) {
System.out.println("Trouble: " + e);
}
}
public static void main(String args[]) {
new CalculatorServer();
}
}
//************************************
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 {
Calculator c = (Calculator)
Naming.lookup(
"rmi://localhost:1099/CalculatorService");
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);
}
}
}
Any advise will be very appreciate.
[ December 27, 2002: Message edited by: Mei Xiao ]
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I copied your code and ran it on my computer using Sun's jdk (1.4.1_01) as well as IBM's (1.4.0) under Linux and it worked fine. I followed the same sequence of steps as you did, so I'm not exactly sure what the problem is. I'm not sure why it's not working for you under windows XP, but I will try running it on an XP machine tomorrow.
Chris
 
Chris De Vries
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've run the CalculatorServer on a Windows XP box using Sun's jdk (version 1.4.1_01) and it worked as well. I'm not sure exactly why you are having a problem running this code.
Chris
 
Chris De Vries
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been able to reproduce the error if I start the rmiregistry with a CLASSPATH that does not include the current path. The rmiregistry has to be able to load the classes from the same location as the client. Usually, in order to assure this I unset the CLASSPATH before running rmiregistry, and I set the java.rmi.server.codebase parameter (as well as the java.rmi.server.hostname, if I am going to be dynamically loading class files over the network) when I run the server. In this case, I think the problem must be that the rmiregistry's classpath does not include the Calculator directory.
 
Michelle Lee
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Chris. I am very appreciate your help!
Mei
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i meet the same problem.
hope help!

but how can set the classpath when run rmiregistry??it not use the classpath of os??
 
kenkin you
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can get registry by yourself,not use the registry tool.
so modify the server class:
///////////////////////
import java.rmi.Naming;
import java.net.*;
import java.rmi.registry.LocateRegistry;
public class CalculatorServer {
public CalculatorServer() {
try {
LocateRegistry.createRegistry(8808) ;///////////here modify!!!
CalculatorImpl c = new CalculatorImpl();
Naming.rebind("rmi://localhost:8808/CalculatorService",c);
System.out.println("sdfsdfsd");
} catch (Exception e) {
System.out.println("Trouble: " + e.getMessage());
}
}
public static void main(String args[]) {
new CalculatorServer();
}
}
///////////
and modify the client's port
//////////////
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 {
Calculator c = (Calculator)
Naming.lookup("rmi://localhost:8808/CalculatorService");///////the port is 8808
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);
}
}
}
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic