java rmic无法正常工作

时间:2017-04-12 11:27:35

标签: java rmi rmic

我正在从代码中的书中学习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位于文件夹printer

enter image description here

1 个答案:

答案 0 :(得分:0)

package chapter4.printers;
  
    

未找到类printers.NullPrinter。 1错误

  
     

但nullprinter.class位于文件夹printer

但它应该在chapter4/printers中,其名称不是printers.NullPrinter。它是chapter4.printers.NullPrinter。这也意味着您应该从包含 rmic目录的目录运行chapter4

rmic chapter4.printers.NullPrinter