我遇到的任何系统都可能不支持 Java 6 的 Desktop.browse() 吗?

发布于 2024-11-28 09:58:00 字数 300 浏览 0 评论 0原文

我看到新的 Desktop 类(我想将其用于其 browser(uri) 方法)包含检查以验证它是否受支持。如果我要为多个操作系统分发应用程序,我是否应该预期它有时会不受支持,并坚持使用类似 此“Bare Bones 浏览器启动” 作为后备方法,或者这种情况极为罕见?我可能会遇到任何特定的操作系统问题?

(我正在针对 Mac/Win/Solaris/Linux 进行分发,但如果您对任何特殊操作系统有所了解,请随意回答。)

I see the new Desktop class (which I'd like to use for its browse(uri) method) includes checks to verify that it's supported. If I'm distributing my application for multiple operating systems, should I expect that it will sometimes be unsupported, and stick in code like this "Bare Bones Browser Launch" as a fallback method, or would that be extremely rare? Any particular OSes for which I might expect problems?

(I'm distributing for Mac/Win/Solaris/Linux, but feel free to answer about any exceptional OSes if you know something about them.)

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

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

发布评论

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

评论(2

酒浓于脸红 2024-12-05 09:58:00

你应该进行防御性编程。

来自如何与桌面类集成

使用isDesktopSupported()方法判断Desktop是否支持
API 可用。 在 Solaris 操作系统和 Linux 上
平台,此 API 依赖于 Gnome 库。如果那些库
不可用,该方法将返回 false

(强调我的)

You should program defensively.

From How to Integrate with the Desktop Class:

Use the isDesktopSupported() method to determine whether the Desktop
API is available. On the Solaris Operating System and the Linux
platform, this API is dependent on Gnome libraries. If those libraries
are unavailable, this method will return false

(emphasis mine)

走走停停 2024-12-05 09:58:00

我认为重点是相反的,Java需要操作系统支持什么?他们给操作系统一个出路,允许 JVM 实现者只返回 false,说它不受支持,然后继续,并且仍然 100% Java 兼容(无论是否是“一次编写,在任何地方运行”)留给你自己评价)。

Bare Bones Browser Launch 等技术或更复杂的库(如 BrowserLauncher)始终只能在有限的操作系统上运行和浏览器,而不是为通用 Java 标准编写的通用代码。

因此,结果是,如果您专门针对的操作系统不支持 Desktop.openURL,请使用像 Bare Bones 启动器这样的技术,但是您必须编写它来专门在该操作系统上工作 - 没有理由认为该技术适用于给定的操作系统和该操作系统上的给定 JVM,它只是代表了我们在 Java 6 之前启动浏览器所必须做的事情。

I think the point is the reverse, what does Java require an OS to support? They are giving an OS an out, by allowing the JVM implementer to just return false, say it is not supported, and move on, and still be 100% Java compliant (whether or not that is "write once run anywhere" I'll leave to your own evaluation).

Techniques like the Bare Bones Browser Launch or more complicated libraries like BrowserLauncher, will always only work on a limited set of OSs and browsers than what generic code that is made for the general Java standard is going to give you.

So the upshot is, use a technique like the Bare Bones launcher if an OS you are specifically targeting doesn't support Desktop.openURL, but then you will have to write it to specifically work on that OS - there is no reason to think that the technique works for a given OS and a given JVM on that OS, it just represents what we used to have to do to launch a browser prior to Java 6.

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