Reputation: 19
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
Upvotes: -1
Views: 1646
Reputation: 310980
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
Upvotes: 0