如何将 java webstart 与 RMI 混合使用?
我想分发一个使用 RMI 的 Webstart 应用程序。
我想避免询问用户RMI服务器的地址,因为分发应用程序的网站也是RMI服务器。
此外,我在构建时不知道服务器的地址,因此必须通过临时配置将地址添加到 JNLP,或者必须在执行时提供地址。 这是首选方式:可以这样做吗?
I want to distribute a webstart application which uses RMI.
I want to avoid to ask the user the address of the RMI server, because the website that distributes the application is also the RMI server.
Furthermore, I don't know the address of the server at build time, therefore the address must be added with ad hoc configuration to the JNLP, or the address must be provided at execution time. This is the preferred way: is it possible to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我还没有完全使用Java RMI(我只使用Java Web Start和 Hessian 二进制协议来执行类似 RMI 的东西),但至少将服务器地址传递给 Web Start 客户端应用程序的部分应该很容易。 当您在应用程序中生成 JNLP 文件时,将地址添加为属性:
然后,在客户端代码中读取该属性:
我假设分发应用程序的网站知道自己的地址:)
编辑 (加上在构建时不知道地址的额外限制):嗯,分发应用程序的网站是动态的还是静态的?
I haven't used Java RMI exactly (I've only used Java Web Start with Hessian binary protocol for doing something like RMI), but at least the part of passing the server address to the Web Start client app should be easy. When you generate the JNLP file in your application, add the address as a property:
Then, in client code read that property:
I assume here the website that distributes the application knows its own address :)
Edit (with the additional limitation of not knowing address at build time): Hmm, Is the website distributing the app a dynamic or static one?
在我工作的地方,我们正是这样做的,并按照 Jonik 的回答将 RMI 注册表的主机名放入 JNLP 中。 在 Java 6u10 或 u11 中,Sun 通过 Webstart 修复了多个安全漏洞,其中包括动态 JNLP 的问题。 为了满足所有安全警告,您必须将 JNLP 的相同副本放入程序的主 jar 中。 这是为了防止第三方将额外的 jar 或参数注入您的代码中。 程序将在没有它的情况下运行,但用户将看到信任通知。
我们确实在构建时知道地址,但遇到其他动态 JNLP 问题,因此不得不为每个可能的运行时设置提供 JNLP 和 JAR。 对于我们来说,这更多的是一个令人头疼的部署问题,而不是客户的问题,但如果您正在签署您的发行版,那么就值得了解这一点。
Where I work we do exactly this, and put the hostname of the RMI registry in the JNLP as per Jonik's answer. In Java 6u10 or u11 Sun closed several security holes with Webstart, including an issue with dynamic JNLP. In order to satisfy all the security warnings you must place an identical copy of your JNLP in the main jar of your program. This is to prevent third parties injecting extra jars or parameters into your code. Programs will run without it, but users will be shown a trust notice.
We do know the address at build time, but had other dynamic JNLP issues and so had to resort to providing a JNLP and a JAR for each possible runtime set-up. This was more of a deployment headache for us, rather than an issue for customers, but if you're signing your distribution then it's worth knowing.
JDK 包含 servlet 的源代码(位于示例/jnlp/servlet 目录中),该 servlet 将适当的值插入到 JNLP 文件中。 您可以使用它将主机名插入到 JNLP 文件中。
The JDK includes source code (in the samples/jnlp/servlet directory) for a servlet that inserts appropriate values into the JNLP file. You can use this to insert the host name into the JNLP file.
我在 jnlp 中使用变量占位符:
并在运行时使用拦截器 servlet 来替换这些占位符,因为 JNLP 被提供给客户端。
I use variable placeholders in my jnlp:
And use an Interceptor servlet to replace these at run time as the JNLP is served to the client.