简体   繁体   中英

Executable RMI JAR file ClassNotFoundException for Stub

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.

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().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM