Pregunta

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();
    }
¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top