WebStart, Images in HTML from Jar
Hello,
I am preparing a Webstart application and I have packed everything into the jar. In the application, I need to display html in an JTextPane and load images from the jar. This works quite well with f. e. <img src="jar:file:context.jar!/figures/erdbeben1.jpg">. Note that context.jar is the executable jar file with all ressources.
Unfortunately it does not work anymore when I deploy the application with webstart. The images in the JTextPane are not displayed anymore (instead red crosses). Does anybody has an idea?
Thanks,
Wolfgang
[578 byte] By [
wlenharda] at [2007-11-27 2:09:29]

# 1
...
> I am preparing a Webstart application and I have
> packed everything into the jar. In the application, I
> need to display html in an JTextPane
Why JTextPane, rather than JEditorPane?*
>..and load images
> from the jar. This works quite well with f. e. <img
> src="jar:file:context.jar!/figures/erdbeben1.jpg">.
* When using JEditorPane, I simply would put the
HTML in the Jar as well, and use HREF's relative
to the web page. Assuming the HTML was located
in jar:file:context.jar!/doce/help.html, you could reduce
the src attribute to..
src="../figures/erdbeben1.jpg"
> Note that context.jar is the executable jar file with
> all ressources.
> Unfortunately it does not work anymore when I deploy
> the application with webstart. The images in the
> JTextPane are not displayed anymore (instead red
> crosses). Does anybody has an idea?
Web start resource storage is (user) configurable
from 'high compression' through to 'no compression'.
I am guessing that at 'no compression', resources
will be stored as loose files, rather than in an archive.
# 2
Hi Andrew,
thanks for the tip.
> Why JTextPane, rather than JEditorPane?*
Well, there is no special reason. I simply reuse the jTextPane, because it is already there.
> >..and load images
> > from the jar. This works quite well with f. e.
> <img
> >
> src="jar:file:context.jar!/figures/erdbeben1.jpg">.
>
> * When using JEditorPane, I simply would put the
> HTML in the Jar as well, and use HREF's relative
> to the web page. Assuming the HTML was located
> in jar:file:context.jar!/doce/help.html, you could
> reduce
> the src attribute to..
>src="../figures/erdbeben1.jpg"
I need to generate the HTML dynamically from within the program. The path src="../figures/erdbeben1.jpg" unfortunately does not work.
> Web start resource storage is (user) configurable
> from 'high compression' through to 'no compression'.
> I am guessing that at 'no compression', resources
> will be stored as loose files, rather than in an
> archive.
Oh, that's a pity, but it gives me a hint, where the problem could be.
# 3
>> HTML in the Jar as well, and use HREF's relative
>> to the web page. Assuming the HTML was located
>> in jar:file:context.jar!/doce/help.html, you could
>> reduce
>> the src attribute to..
>> src="../figures/erdbeben1.jpg"
> I need to generate the HTML dynamically from
> within the program. The path src="../figures/erdbeben1.jpg"
> unfortunately does not work.
That would obviously not work, unless the HTML resided
in a directory within the jar file (note the '..' which
means 'one directory up').
What might work is to add a document base* to the HTML
(a document base of '/' to indicate the 'root'), then
<img src='/figures/erdbeben1.jpg'>
* http://www.htmlhelp.org/reference/html40/head/base.html
# 4
naturally, when running from Java Web Start "file:context.jar" is not the URL to the jar.
You should use:
ClassLoader cl = thread.currentThread().getContextClassLoader();
URL imageURL = cl.getResource("figures/erdbeben1.jp");
then imageURL will be the URL to the image however context.jar is run.
/Andy