PDA

Click to See Complete Forum and Search --> : Read images inside jar-file


Grimling
Oct 29th, 2009, 01:45 PM
Hello

I'm making a program and I want to put the program in a JAR-file. But when I put it in one, the images aren't found. I did try many things, such as the getClass().getSourceAsStream(Filename), but no one works. Can anyone help me, please?

this is the code(I show one example, the others are similar):
The main-class App.class calls a method in the class Image

saveIcon = new ImageIcon((Image)ImageIO.read(new BufferedInputStream(this.getClass().getResourceAsStream("/save.png"))));
This is the file-content:
App.jar
App.class
Image.class
save.png

Thanks in advance

Grimling

kfcSmitty
Oct 29th, 2009, 02:24 PM
This (http://www.javaworld.com/javaworld/javatips/jw-javatip49.html) seems to have a way to handle it.

But why are you putting it into the jar file? Why not use an installer to place the files in an appropriate directory?

Grimling
Oct 29th, 2009, 02:27 PM
Thanks, I will try it. I have heard of installers, but I don't understand it very well. If I use an installer, is it than platform-independent? And is there a way to start the program by simple double-click on it? If I distribute the program, users don't want to open the commandline.

mvg

Grimling

ComputerJy
Oct 30th, 2009, 06:38 AM
Well you'll have to associate the jar files with java. Otherwise they'll open a extraction tool or even Nokia PC Suite. you can always put your command line script in a bat file (and a bash file for Mac and Linux) so users can start your app with a single click

Grimling
Oct 31st, 2009, 08:03 AM
Thanks, the program works now when you download it and save it to a hard disk or USB-stick or whatever...But not when it is running from in the browser. There's no advantage by installing it, but, your explication can help me with another project.


Grimling

PS: If you are interested, this is the link to the page where you can download the program, the page is in Dutch, but it's the 'Download'-button :p
http://floriskint.000space.com/artikels/FMathApp.php

ComputerJy
Oct 31st, 2009, 10:04 AM
If it runs in Explorer it runs in IE. Other browsers usually use explorer to open files for windows. In most Linux distros the mime type is the major factor to opening a file and I think Macs work the same way

Grimling
Oct 31st, 2009, 10:09 AM
I tried it with Firefox and Opera. Neither it works in IE.

Grimling