2011-10-31 2 views
2

자바에서 링크를 시작하려고합니다.JAR에서 링크 시작 : "Firefox가 www. % u.com에서 서버를 찾을 수 없습니다."

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에서 jar로 이동하면 라이브러리가 누락되지 않습니다. 단순히 Firefox 나 다른 브라우저에서 % U를 링크로 표시합니다.

어쨌든 이것을 고칠 수 있습니까?

전체 코드는 http://hummingbird-hibl.googlecode.com/svn/trunk/ 데스크탑은 지원되지 않습니다

+0

이것은 주제가 아니지만 '링크'가 정적 인 이유는 무엇입니까? LinkLauncher의 다른 인스턴스에서 Link 객체를 공유 하시겠습니까? – gigadot

+0

'launchLink' 메소드를 정적으로 만들어서 LinkLauncher의 객체를 만들지 않고 링크를 점심을 먹을 수 있다고 생각합니다. 그렇지 않으면 링크를 점심 먹기 위해'LinkLauncher'의 두 개의 객체를 만들어야합니다. – gigadot

+0

'(space) '로 시작하는 것이 유효한 URI 일 수있는 이유는 무엇입니까? 그 코드가 예외를 무시하는 이유 더 빨리 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –

답변

1

에서 사용할 수 있지만 자바는 주장했다. 이렇게 코드를 수정 했으므로 마지막으로 시도 할 것은 "지원되는"브라우저를 시작하는 것입니다.

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) { 
         } 
        } 
       } 
      } 
     } 
    } 
} 
+0

'Shell' 클래스는 NetBeans 7.3에서 사용할 수 없습니다. – MountainX

관련 문제