-1

i am learning rmi for practice from a book in book following code but rmic not working

package chapter4.printers;

import chapter4.*;
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;

public class NullPrinter extends UnicastRemoteObject implements Printer {

    private PrintWriter log;
    public NullPrinter(OutputStream log) throws RemoteException {
        this.log = new PrintWriter(log);
    }

    @Override
    public boolean printerAvailable() throws RemoteException {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public boolean printDocument(DocumentDescription document) throws RemoteException, PrinterException {
        // TODO Auto-generated method stub
        if (null == log) {
            throw new NoLogException();
        }

        if (null == document) {
            throw new NoDocumentException();
        }
        log.println("Printed file");
        log.flush();
        if(log.checkError()) {
            throw new CantWriteToLogException();
        }
        return true;
    }

    private class NoLogException extends PrinterException {
        public NoLogException() {
            super(0, "Null printer failure. No log to record" +
        " print request.");
        }
    }

    private class NoDocumentException extends PrinterException {
        public NoDocumentException() {
            super(0, "Null printer failure. No document receive" +
                    " as part of print request.");
        }
    }

    private class CantWriteToLogException extends PrinterException {
        public CantWriteToLogException() {
            super(0, "Null printer failure. Attempt to record " +
        "print request to log failed.");
        }
    }
}


package chapter4.applications;

import chapter4.printers.*;
import chapter4.*;
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
public class SimpleServer implements NetworkConstants {
    public static void main(String[] args) {
        try {
            File logFile = new File("serverLogFile");
            OutputStream outputStream = 
                    new FileOutputStream(logFile);
            Printer printer =
                    new NullPrinter(outputStream);

              Naming.rebind(DEFAULT_PRINTER_NAME, printer);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Messages:

Warning: generation and use of skeletons and static stubs for JRMP is deprecated. Skeletons are unnecessary, and static stubs have been superseded by dynamically generated stubs. Users are encouraged to migrate away from using rmic to generate skeletons and static stubs. See the documentation for java.rmi.server.UnicastRemoteObject.

error: Class printers.NullPrinter not found. 1 error

but the nullprinter.class is there in folder printer

enter image description here

user207421
  • 305,947
  • 44
  • 307
  • 483
faisal
  • 19
  • 1
  • 8

1 Answers1

0
package chapter4.printers;

Class printers.NullPrinter not found. 1 error

but the nullprinter.class is there in folder printer

But it should be in chapter4/printers, and its name is not printers.NullPrinter. It is chapter4.printers.NullPrinter. Which also means you should be running rmic from the directory containing the chapter4 directory:

rmic chapter4.printers.NullPrinter
user207421
  • 305,947
  • 44
  • 307
  • 483
  • i don't understand can make me more clear what should i write in argument my path to NullPrinter.class file is E:\eclipseneonworkspace\rmi\bin\chapter4\printers – faisal Apr 13 '17 at 05:07
  • Your path should be `E:\eclipseonworkspace\rmi\bin`, which is the one that contains `chapter4`, as I already said, and I have already given you what to write in the argument. All this seems pretty clear already. – user207421 Apr 13 '17 at 06:06
  • can you tell me where to set the path in eclipse for rmic and E:\eclipseonworkspace\rmi\bin in old book it is not written i have read it but it is not there i got stuck in eclipse settings – faisal Apr 18 '17 at 15:53