gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:50:30 24 4
gpt4 key购买 nike

我正在尝试从 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com