java.rmi.ServerException:服务器线程中发生RemoteException(ClassNotFoundException)
以下方法:java.rmi.ServerException:服务器线程中发生RemoteException(ClassNotFoundException),java,exception,rmi,Java,Exception,Rmi,以下方法: private void startServer() { // snippet that starts the server on the local machine try { RemoteMethodImpl impl = new RemoteMethodImpl(); Naming.rebind( "Illusive-Server" , impl ); }catch(Exception exc) { JOpti
private void startServer() { // snippet that starts the server on the local machine
try {
RemoteMethodImpl impl = new RemoteMethodImpl();
Naming.rebind( "Illusive-Server" , impl );
}catch(Exception exc) {
JOptionPane.showMessageDialog(this, "Problem starting the server", "Error", JOptionPane.ERROR_MESSAGE);
System.out.println(exc);
}
}
引发此异常:java.rmi.ServerException:服务器线程中发生RemoteException;嵌套异常是:
java.rmi.UnmarshalException:错误解组参数;嵌套异常是:
java.lang.ClassNotFoundException:Interfaces.RemoteMethodIntf
当我启动我的项目时,JOptionPane中的消息会告诉我启动服务器时出现问题,然后是上述异常。这可能是什么原因
我不明白,当我导入了正确的包时,为什么最后一个异常语句说class not found exc有四个异常情况
UnicastRemoteObject
的前言中描述的步骤使其变得不必要LocateRegistry.createRegistry()在服务器JVM中启动注册表。
UnicastRemoteObject的Javadoc序言中所述。
但是,您可能仍然会遇到远程接口本身或它所依赖的类的相同问题,在这种情况下,上述1-3仍然适用于该类-
例如,您的java文件考虑d驱动器< /LI>
- 启动RMID注册表驱动器(示例D:\Start rmiregistry),然后不要在其他驱动器上启动RMI注册表,这将产生上述错误
(无论文件位于何处,请启动
rmiregistry
)您可以从任何位置启动rmiregistry,但必须确保编译的类已经在类路径中。例如:-
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes <ENTER>
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c: <ENTER>
C:\>rmiregistry
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c:
C:\>注册中心
上述措施应该可以很好地发挥作用
通常,如果从编译类的根位置启动rmiregistry(上面的示例是E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes),这将起作用,因为。(点-当前目录)已在类路径中设置
但一旦你离开。(点-当前目录)从类路径,上述工作条件也将失败
希望我已经详细解释过了。我遇到了同样的问题,不同的解决方案对我有效。我运行了两个不同的IntelliJ项目,每个项目中都有一个接口副本。其中一个在包中,另一个不在包中,这就是导致此错误的原因 解决方案:
- 确保接口副本不在包中李>
- 确保接口副本具有完全相同的包名
设置类路径=%classpath%
set classpath=C:\compiler
set classpath=C:\compiler\libro\cap07\rmi\hello\hello.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Server.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Client.java
- (多功能一体式线集:
set classpath=%classpath%;C:\compiler;C:\compiler\libro\cap07\rmi\hello\hello.java;C:\compiler\libro\cap07\rmi\hello\Server.java;C:\compiler\libro\cap07\rmi\hello\Client.java)
- (我不确定.java文件是否正确,但我也写了它们以表示怀疑)
javac-dc:\compiler Hello.java Server.java Client.java
进行编译。其中C:\compiler
是Eclipse IDE上类似src的根目录
三,。我运行了启动注册表
行。(不管你在哪里运行,都是一样的)
第四。我跑:
start java-classpath C:\compiler-Djava.rmi.server.codebase=文件:C:\compiler/libro.cap07.rmi.hello.server
您已经知道C:\compiler
,但是您需要在最后一个位置定义包地址,以便命令可以找到.class文件。打开任何.java文件并复制不带packages sentense的包地址。当您打开src目录(在我的例子中是C:\compiler)时,您将看到创建的所有目录序列。正确创建此命令行后,无论在何处运行它,C:,D:,src,以及它将在何处运行
五号。最后,我使用以下命令运行客户端类:
java-classpath C:\compiler libro.cap07.rmi.hello.Client
总之,如果classpath变量没有创建,或者创建错误,或者第四点的语句没有得到很好的处理,JVM就会抛出相同或类似的错误。在那里搜索
(对不起,我的英语。)@SuhailGupta参见
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes <ENTER>
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c: <ENTER>
C:\>rmiregistry