how to open help file in executable jar

醉酒当歌 提交于 2019-12-25 01:19:16

问题


I want to open .chm help file when click on Help button. When i do it in eclipse its working good. but when i create executable jar file then its giving error that "can not open file". this is my code:

String path = Toolkit.getDefaultToolkit().getClass().getResource("/resources/UserAccountHelpNew.chm").getPath();

    String path1 = path.substring(1);
    System.out.println(path1);

    try {
        Process process = Runtime.getRuntime().exec("hh.exe "+path1);
        process.waitFor();
    } catch (InterruptedException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

回答1:


hh.exe can't open files in a jar. You need to either write some code copy the contents of Toolkit.getDefaultToolkit().getClass().getResource("/resources/UserAcountHelpNew.chm") to a place on the file system, or distribute this file alongside the executable jar.

The reason it works in Eclipse is because you probably have the file on the file system. When your working directory changes, hh.exe can no longer find the file.



来源:https://stackoverflow.com/questions/9823096/how-to-open-help-file-in-executable-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!