如何获得 Linux 下支持的桌面类? [英] How to get Desktop class supported under Linux?

查看:29
本文介绍了如何获得 Linux 下支持的桌面类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Java 应用程序,我想在用户的默认 Internet 浏览器中从我的程序中打开一个链接.我尝试像这样使用桌面类:

I am writing a java application and I want to open a link from my program in user's default internet browser. I tried to use class Desktop like this :

if (Desktop.isDesktopSupported()) {
    Desktop desktop = Desktop.getDesktop();
    if (desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
        try {
            URI uri = new URI(url); // url is a string containing the URL
            desktop.browse(uri);
        }
        catch (URISyntaxException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

但是首先如果返回false.我的操作系统是最新版本的 Ubuntu.有人知道如何在 Java 中支持该桌面吗?

However first if returns false. My OS is newest version of Ubuntu. Does anybody know how to get that Desktop supported in java?

推荐答案

本质上,您不需要在 Gnome 桌面上运行 Java 代码.您只需要安装 Gnome 库,以便 Java 识别它(正如 ccheneson 所说).

You don't need to run the java code on the Gnome desktop, per se. You just need to have the Gnome libraries installed so that Java recognizes it (as ccheneson said).

如果您运行的是新版本的 Ubuntu,它不会附带 gnome 库,因为它使用 Unity.尝试安装 libgnome2-0.当我安装它时,它附带了一些其他软件包(libbonobo2-0libbonobo2-commonlibgnomevfs2-0libgnomevfs2-common) 所以我不知道 libgnome2-0 是否足够,或者是否还需要其他任何一个.但是后来我的 12.04 Ubuntu 系统被 Java API 识别了.

If you are running a new version of Ubuntu, it doesn't come with the gnome libraries because it uses Unity. Try installing libgnome2-0. When I installed it a few other packages came with it (libbonobo2-0, libbonobo2-common, libgnomevfs2-0, libgnomevfs2-common) so I don't know if libgnome2-0 is sufficient or if any of the others are necessary as well. But then my 12.04 Ubuntu system was recognized by the Java API.

我知道这篇文章相对较旧 - 但这个问题在网上的很多地方都有,我找到正确"答案的唯一地方(对我来说)是 这里

I know this post is relatively old - but this question is in a variety of places online and the only place I found the "correct" answer (for me) was here

这篇关于如何获得 Linux 下支持的桌面类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆