I have an html file called snake.html that I would like to put inside a jar. When the jar is run the main class should open this html file in the browser. I have tried:
public static void main(String[] args) throws IOException, URISyntaxException {
URL url = Snake.class.getResource("/WebContent/snake.html");
System.out.println(url);
// relative to the class location
Desktop.getDesktop().browse(url.toURI());
}
Which works if I just run this code but when I jar it (and the html file) I get the following exception:
Exception in thread "main" java.io.IOException: Failed to mail or browse
jar:file:/Users/~user~/Desktop/Snake%20v0.1.jar!/WebContent/snake.html.
Error code: -10814
at apple.awt.CDesktopPeer.lsOpen(CDesktopPeer.java:52)
at apple.awt.CDesktopPeer.browse(CDesktopPeer.java:45)
at java.awt.Desktop.browse(Desktop.java:368)
at snake.Snake.main(Snake.java:26)
Im wondering if I have a classpath issue or maybe Im not directing the jar to the file correctly. THe jar has two directories, snake and WebContent. Snake has the snake.class file and WebContent has snake.html.
Any and all help/criticism appreciated.
You’ll have to devompress the file first.
Something like: