Results 1 to 7 of 7

Thread: Read images inside jar-file

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    4

    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

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    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?

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    4

    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
    Last edited by Grimling; Oct 29th, 2009 at 02:36 PM.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    4

    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
    http://floriskint.000space.com/artikels/FMathApp.php

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    4

    Re: Read images inside jar-file

    I tried it with Firefox and Opera. Neither it works in IE.

    Grimling

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width