wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How to display HTML in jar file with default browser with desktop.browse(URI)  ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to display HTML in jar file with default browser with desktop.browse(URI)  ?" Watch "How to display HTML in jar file with default browser with desktop.browse(URI)  ?" New topic
Author

How to display HTML in jar file with default browser with desktop.browse(URI) ?

Chris Kimball
Ranch Hand

Joined: Apr 23, 2012
Posts: 32



My app can display an HTML file with the java.awt.desktop.browse(URI) method correctly from a file hierarchy. Here, the URL from URLCLassLoader is converted by the URL.toURI method. Alas, this doesn't work when the classes are bundled in a jar file.

The URL is jar:file:/xxx.jar!/a/b.html (Note the ! after the jar).

How can I display the internal HTML file with the very convenient java.awt.desktop.browse(URI) method?

Thanks,

Chris Kimball

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

You'll need to extract it to an actual file, then display that. You can use File.createTempFile to get a unique temporary file, and if you use deleteOnExit() that file will be removed when your application shuts down (if possible).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Chris Kimball
Ranch Hand

Joined: Apr 23, 2012
Posts: 32

Thanks!

Didn't know about the createTemporaryFile / deletOnExit methods, either.

Chris
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

You're welcome
 
Don't get me started about those stupid light bulbs.
 
subject: How to display HTML in jar file with default browser with desktop.browse(URI) ?
 
Similar Threads
Deploy time exception - Key Attribute required for element exception
context root getting changed
tag library doubt
Running an applet in Wicket 1.3.5
ANT Jar blues