It is possible to for Desktop.open(File f)
to reference a file located within a JAR?
I tried using ClassLoader.getResource(String s)
, converting it to a URI, then creating a File from it. But this results in IllegalArgumentException: URI is not hierarchical
.
URL url = ClassLoader.getSystemClassLoader().getResource(...);
System.out.println("url=" + url); // url is valid
Desktop.getDesktop().open(new File(url.toURI()));
A possibility is the answer at JavaRanch, which is to create a temporary file from the resource within the JAR – not very elegant.
This is running on Windows XP.