如何在Linux下支持Desktop类? [英] How to get Desktop class supported under Linux?

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

问题描述

我正在编写一个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-0 libbonobo2-common libgnomevfs2-0 libgnomevfs2-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下支持Desktop类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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