Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top