• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 35
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 22683
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!

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

Chris
 
Rob Spoor
Sheriff
Posts: 22683
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
His brain is the size of a cherry pit! About the size of this ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic