javac 不为 RMI 创建存根

发布于 2024-10-13 01:36:52 字数 619 浏览 2 评论 0原文

我正在为一个大学项目寻找 RMI,但遇到了一些问题。根据我的阅读,java 版本 5 及更高版本应该自动生成必要的存根文件(据我所知,之前需要一个额外的步骤)。

但是,在遵循本教程之后 http:// /download.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html 并使用 Javac 编译我的类,我只得到了标准类文件,没有我的存根的迹象文件。

当我尝试运行我的项目时,这得到了证实,我的应用程序崩溃,说它找不到任何存根文件。我错过了什么吗?

注意,运行 java -version 给了我这个:

java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)

Im looking into RMI for a university project, and ive run into a bit of a problem. From what ive read, java version 5 and up should generate the necessary stub files automatically (as i understand there was previously an additional step required).

However after following this tutorial here http://download.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html and compiling my classes with Javac, ive only got the standard class files, no sign of my stub files.

This is confirmed when i try and run my project, my application crashes saying that it cant find any stub files. Am i missing something?

NB, running java -version gives me this:

java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似梦非梦 2024-10-20 01:36:52

使用了类似的东西

RemoteInterface stub =
(RemoteInterface) UnicastRemoteObject.exportObject(server);

我相信您在服务器中

RemoteInterface stub =
(RemoteInterface) UnicastRemoteObject.exportObject(server, 0);

,而不是注意 exportObject() 的两个参数 - 第二个版本返回不同的类型。这确实对我来说很重要。

I believe you used something like

RemoteInterface stub =
(RemoteInterface) UnicastRemoteObject.exportObject(server);

in your server, instead of

RemoteInterface stub =
(RemoteInterface) UnicastRemoteObject.exportObject(server, 0);

Note two arguments to exportObject() -- second version returns different type. It indeed make difference for me.

如果没结果 2024-10-20 01:36:52

>= 5.0 jvm 上不需要或生成存根。
可能有些路​​径是错误的,教程对于如何设置目录/路径以及从哪里运行东西不是很清楚。

以下内容对我有用:

~/tmp$ mkdir -p hello/example
~/tmp$ vim hello/example/Hello.java [copy/paste the code of Hello.java here]
~/tmp$ vim hello/example/Server.java [copy/paste the code of Server.java here]
~/tmp$ vim hello/example/Client.java [copy/paste the code of Client.java here]
~/tmp$ mkdir build
~/tmp$ javac -d build/   hello/example/*.java
~/tmp$ rmiregistry &
~/tmp$ java -classpath build -Djava.rmi.server.codebase=file:build/ example.hello.Server &
Server ready
~/tmp$ java  -classpath build  example.hello.Client
response: Hello, world!

这里重要的部分是构建和运行内容时您所处的目录,以及将正确的目录传递给类路径和-Djava.rmi.server.codebase。

stubs arn't needed or generated on >= 5.0 jvms.
It might be that some of the paths are wrong, the tutorial isn't very clear on all how to set up the directories/paths and where you run stuff from.

The following worked for me:

~/tmp$ mkdir -p hello/example
~/tmp$ vim hello/example/Hello.java [copy/paste the code of Hello.java here]
~/tmp$ vim hello/example/Server.java [copy/paste the code of Server.java here]
~/tmp$ vim hello/example/Client.java [copy/paste the code of Client.java here]
~/tmp$ mkdir build
~/tmp$ javac -d build/   hello/example/*.java
~/tmp$ rmiregistry &
~/tmp$ java -classpath build -Djava.rmi.server.codebase=file:build/ example.hello.Server &
Server ready
~/tmp$ java  -classpath build  example.hello.Client
response: Hello, world!

The important part here is which directory you stand in when building and running stuff, as well as passing the proper directories to classpath and -Djava.rmi.server.codebase.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文