how to open help file in executable jar

2019-09-08 11:47发布

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条回答
孤傲高冷的网名
2楼-- · 2019-09-08 11:52

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.

查看更多
登录 后发表回答