启动并运行 Java RMI
我正在尝试运行此 Sun 教程中的示例代码:
http://download.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html
我已将他们的所有代码完全复制到 Eclipse 项目中并运行'rmiregistry &'从终端(我正在运行 OSX)。
当我尝试运行服务器时,
Server exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: suntut.Hello
#java on freenode 向我保证,注册表本身不需要了解有关我的类的任何信息。但似乎更奇怪的是,问题出在我的文件名或其他东西上——所有三个类在编译时都能很好地看到彼此,它们都在 Eclipse 项目中的同一个包中,等等。任何人都可以帮助我开始诊断这个问题吗?
更新: 我也尝试从命令行运行它。从 /Users/[me]/workspace/[Projectname]/testing/ 我运行
java suntut/Server
并得到了完全相同的错误。 (这是在使用 javac 成功编译所有内容之后)
I'm trying to run the sample code from this Sun tutorial:
http://download.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html
I've copied all their code exactly into an Eclipse project and run 'rmiregistry &' from terminal (I'm running OSX).
When I try to run the server, I get
Server exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: suntut.Hello
I have been assured by #java on freenode that the registry itself does not need to know anything about my classes. But it seems even stranger that the issue is with my filenames or something -- all three classes see each other just fine at compile time, they are all in the same package in an Eclipse project, etc. Can anyone help me start diagnosing this?
Update:
I tried running it from the command line as well. From /Users/[me]/workspace/[Projectname]/testing/ I ran
java suntut/Server
and got the exact same error. (This is after successfully compiling everything with javac)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这是您第一次使用 RMI,我建议您按照说明启动,不要更改任何内容(即,甚至不更改包名称)。这使得其他人可以轻松地帮助您,并且您犯错误的可能性也很低。
暂时放弃 Eclipse 并尝试按照教程中的说明进行操作。使用 IDE,您最终会将 IDE 和实际问题混为一谈。也就是说,运行 Java 类时必须使用完全限定的类名。如果测试是包名称的一部分,则必须使用
testing.suntut.Server
而不仅仅是suntut.Server
。If this is your first time with RMI, I'd recommend following the instructions to the boot without changing anything (i.e. not even the package name). This makes it simple for others to help you out and the chances of you making a mistake are low.
For the time being, do away with Eclipse and try following the instructions in the tutorial. Using an IDE, you'll end up mixing IDE and the real issues. That being said, you have to use the fully qualified class name when running a Java class. If testing is part of the package name, you have to use
testing.suntut.Server
instead of justsuntut.Server
.