Search code examples
javarmi

jGuru RMI example don't compile


I'm trying to run jGuru examples of RMI from the tutorial at (http://java.sun.com/developer/onlineTraining/rmi/RMI.html) but they didn't compile in the command line, so I can't run rmic and advance the tutorial:

$javac Calculator.java

$javac CalculatorImpl.java
CalculatorImpl.java:6: cannot find symbol
symbol: class Calculator
    implements Calculator {
               ^
1 error

both classes are exactly like they're in the jguru tutorial: Interface:

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;
}

Class:

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;
    }
}

Environment vars: (@Windows XP)

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
CLASSPATH=C:\Program Files\Java\jdk1.6.0_20
Path=C:\Program Files\Java\jdk1.6.0_20\;...

Solution

  • You certainly forgot to import your interface. You should check that.


    For example, this is the compilation error given if the Lol class isn't imported :

    Test.java:3: cannot find symbol  
    symbol  : class Lol  
    location: class Test  
             static Lol l;  
                    ^