bancer
bancer

Reputation: 7525

How to open html or chm file from jar?

I have "help.html" file in resource directory. I can open it from Eclipse these ways:

  1. As chm file:

    Runtime.getRuntime().exec("hh.exe res/help.html");

  2. As html file by default system browser:

    URL resource = getClass().getClassLoader().getResource("help.html");
    File file = new File(resource.toURI());
    Desktop.getDesktop().open(file);

When I create executable jar file I cannot open "help.html" anymore. Is there any way to open the file from jar archive? I know I can save "help.html" outside jar and open it but this is not what I want. I want to have a single jar file.

Upvotes: 1

Views: 1725

Answers (1)

Vivien Barousse
Vivien Barousse

Reputation: 20875

You can't do that. This is beacause the system (hh.exe or the default browser) can't open a file that is stored inside your JAR.

The best solution IMHO is to copy the resource to the system temporary folder, and then run either command to open it. This way, your file is still stored inside the JAR, but can be copied to a location outside of it just when it needs to be opened.

Upvotes: 1

Related Questions