我正在按照代码从书中的书中学习 rmi 进行练习,但 rmic 不起作用
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();
}
}
}
留言:
警告:不推荐为 JRMP 生成和使用骨架和静态存根。骨架是不必要的,静态存根已被动态生成的存根取代。鼓励用户放弃使用 rmic 来生成骨架和静态存根。请参阅 java.rmi.server.UnicastRemoteObject 的文档。
错误:找不到类 printers.NullPrinter。1 个错误
但 nullprinter.class 在文件夹打印机中