问题
I have a working RMI server program, which I can compile and execute directly from the .class files.
However, when I am trying to create a JAR files for each of these programs, I got a ClassNotFoundException: ChatImpl_Stub
leading to a RemoteException
on execution.
My manifest is (plus an empty line at the end) :
Main-Class: Server
Class-Path: chat-RMI-common.jar
Where chat-RMI-common is a JAR file containing the Chat Interface for the client.
I successfully created the JAR with :
jar cvmf ..\MANIFEST.MF chat-RMI-server.jar *.class
The server JAR does contain ChatImpl_Stub. However the exception shows up when I am trying to launch the JAR file :
java -Djava.rmi.server.codebase="file:chat-RMI-common.jar file:chat-RMI-server.jar"
-Djava.security.policy=..\security.policy
-jar chat-RMI-server.jar
The exception appears when the Naming.rebind
function, involving ChatImpl, is called (at the beginning of the program).
My security policy :
grant {
permission java.security.AllPermission;
}
What am I still forgetting? Thanks in advance for your time.
回答1:
Have a good look at the stack trace. The Registry can't find the class. It needs to be on the Registry's CLASSPATH. So you either need to start the Registry with the right JARs on its CLASSPATH, or, better still start it inside the server JVM, with LocateRegistry.createRegistry().
来源:https://stackoverflow.com/questions/21001486/executable-rmi-jar-file-classnotfoundexception-for-stub