我不知道爲什麼這是有運行時錯誤,我已經搜索了這個問題,它說在編譯時可用的類在運行時不再可用。java.lang.NoClassDefFoundError
這是代碼:
package examples.RMIShape;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
//import java.rmi.server.UnicastRemoteObject;
public class ShapeListServer {
public static void main(String args[]){
// System.setSecurityManager(new RMISecurityManager());
System.out.println("Main OK");
try{
ShapeList aShapelist = new ShapeListServant();
System.out.println("After create");
String registryURL = "rmi://localhost:" + "/ShapeList";
startRegistry();
Naming.rebind(registryURL, aShapelist);
System.out.println("ShapeList server ready");
}catch(Exception e) {
System.out.println("ShapeList server main " + e.getMessage());
}
}
// This method starts a RMI registry on the local host, if it
// does not already exists at the specified port number.
private static void startRegistry()throws RemoteException{
Registry registry;
try {
registry = LocateRegistry.getRegistry();
registry.list(); // This call will throw an exception
// if the registry does not already exist
}
catch (RemoteException e) {
// No valid registry at that port.
System.out.println ("RMI registry cannot be located at port " + Registry.REGISTRY_PORT);
registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
System.out.println("RMI registry created at port " + Registry.REGISTRY_PORT);
}
} // end startRegistry
}
谷歌說得對,只需找到這些問題的答案,你應該很好。你是哪一類的錯誤?在哪個類中存在的jar?最後是你的類路徑中的jar嗎? –
請發佈完整的錯誤消息,包括堆棧跟蹤;它也告訴你什麼類缺失。在運行程序時,必須確保該類在類路徑中。 – Jesper