Executable RMI JAR file ClassNotFoundException for Stub

别说谁变了你拦得住时间么 提交于 2019-12-13 02:09:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!