我遇到的任何系统都可能不支持 Java 6 的 Desktop.browse() 吗?
我看到新的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你应该进行防御性编程。
来自如何与桌面类集成:
(强调我的)
You should program defensively.
From How to Integrate with the Desktop Class:
(emphasis mine)
我认为重点是相反的,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.