File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Chris Kimball
Ranch Hand
Posts: 35
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Chris Kimball
Ranch Hand
Posts: 35
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

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

Chris
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic