Read images inside jar-file
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
HTML Code:
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
Re: Read images inside jar-file
This 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?
Re: Read images inside jar-file
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
Re: Read images inside jar-file
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
Re: Read images inside jar-file
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
Re: Read images inside jar-file
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
Re: Read images inside jar-file
I tried it with Firefox and Opera. Neither it works in IE.
Grimling