java - 从 JAR : "Firefox can' t find the server at www. %u.com 启动链接。”

标签 java firefox hyperlink

我正在尝试从 Java 启动链接。我这样做的方式是像这样调用 firefox、internet explorer 或 safari:

public class LinkLauncher implements Runnable  {
    static String Link;
    public void launchLink(String link){
        Link = " \""+link+"\"";
        Runnable runnable = new LinkLauncher();
        Thread thread = new Thread(runnable);
        thread.start();
    }
    public void run() {
         if (Desktop.isDesktopSupported()) {
            Desktop desktop;
            desktop = Desktop.getDesktop();
            URI uri = null;
            try {
                uri = new URI(Link);
                 desktop.browse(uri);
            } catch (IOException ioe) {
            } catch (URISyntaxException use) {
            }
        } else {
            Shell Shell = new Shell();
            String Cmd[]={"firefox", Link};
            String LaunchRes=Shell.sendShellCommand(Cmd);
            if (LaunchRes.contains("CritERROR!!!")){
                String MCmd[]={"open" , Link};
                String MLaunchRes=Shell.sendShellCommand(MCmd);
                if (MLaunchRes.contains("CritERROR!!!")){
                    String WCmd[]={"explorer", Link};
                    Shell.sendShellCommand(WCmd);
                }
            }
        }
    }

}

此方法在 NetBeans 中非常有效,但是一旦我创建了一个 java jar 文件,它就停止工作了。

当我从 netbeans 转到 jar 时,它没有丢失任何库。它只是将 %U 显示为 Firefox 或其他浏览器中的链接。

有什么办法可以解决这个问题吗?

完整代码可在 http://hummingbird-hibl.googlecode.com/svn/trunk/ 获得

最佳答案

不支持桌面,但 Java 声称支持。我像这样修改了代码,因此它尝试的最后一件事是启动“支持的”浏览器。

    public class LinkLauncher implements Runnable  {
    static String Link;
    public void launchLink(String link){
        Link = link;
        Runnable runnable = new LinkLauncher();
        Thread thread = new Thread(runnable);
        thread.start();
    }
    public void run() {

        Shell Shell = new Shell();
        String Cmd[]={"firefox", Link};
        String LaunchRes=Shell.sendShellCommand(Cmd);
        if (LaunchRes.contains("CritERROR!!!")){
            String MCmd[]={"open" , Link};
            String MLaunchRes=Shell.sendShellCommand(MCmd);
            if (MLaunchRes.contains("CritERROR!!!")){
                String WCmd[]={"explorer", Link};
                String WLaunchRes=Shell.sendShellCommand(WCmd);
                if (WLaunchRes.contains("CritERROR!!!")){
                     if (Desktop.isDesktopSupported()) {
                        Desktop desktop;
                        desktop = Desktop.getDesktop();
                        URI uri = null;
                        try {
                            uri = new URI(Link);
                             desktop.browse(uri);
                        } catch (IOException ioe) {
                        } catch (URISyntaxException use) {
                        }
                     }
                }
            }
        }
    }
}

关于java - 从 JAR : "Firefox can' t find the server at www. %u.com 启动链接。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7954420/

相关文章:

javascript - 在 Firefox Quantum 中刷新页面后丢失 window.history.state

javascript - 为什么使用console.profile()时无法得到正确答案?

rest - 如何为POST端点创建链接关系?

javascript - 如何使用链接而不是按钮打开模式弹出窗口

java - Java swing 代码中的问题

java - 子类化输入流和输出流

java - Xlib : extension "RANDR" missing on display ":99"

php - 如何通过选择文档中较早的链接来查看隐藏的 <span> ?

java - Selenium HtmlUnitDriver 程序中捕获的 SocketException

java.lang.NoSuchMethodError : java. 语言.NoSuchMethodError