Results 1 to 4 of 4
  1. #1
    dunafrothint is offline Member
    Join Date
    Oct 2009
    Posts
    26
    Rep Power
    0

    Default How to add images to a .jar file?

    Hi,

    I'm wondering if there is a way to build a jar file that can be built with images and how to access those images? Right now I am using an ImageIcon("Images/1.png") and copying the images folder into the dist jar folder after I clean and build.

    I'm hoping there is a better way to have a jar application accessing images without having to give a specific path, such as "C:/Users/User/MyPictures/Images/1.png").

    Thanks in advance!

    ~Jamie

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dunafrothint View Post
    Hi,

    I'm wondering if there is a way to build a jar file that can be built with images and how to access those images? Right now I am using an ImageIcon("Images/1.png") and copying the images folder into the dist jar folder after I clean and build.

    I'm hoping there is a better way to have a jar application accessing images without having to give a specific path, such as "C:/Users/User/MyPictures/Images/1.png").

    Thanks in advance!

    ~Jamie
    Images (and text files or whatever) are resources to your application. Get a Class object from a class in your application and read the API documentation for the Class.getResoure( ... ) and/or Class.getResourceAsStream( ... ) methods. Those resources can be stored in a jar, there is no need to store them in separate files in your file system.

    kind regards,

    Jos

  3. #3
    dunafrothint is offline Member
    Join Date
    Oct 2009
    Posts
    26
    Rep Power
    0

    Default

    Hmmm. I just build my jar using the simple Netbeans two-click method. Is there something I can do to edit the build of the jar to include the resources?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dunafrothint View Post
    Hmmm. I just build my jar using the simple Netbeans two-click method. Is there something I can do to edit the build of the jar to include the resources?
    I don't know Netbeans but maybe your images are already stored in that jar. Outside of Netbeans type:

    Java Code:
    jar tvf YourJar.jar
    ... and see if your images are there.

    kind regards,

    Jos

Similar Threads

  1. Images in JAR File (via Eclipse)
    By AndrewM16921 in forum New To Java
    Replies: 13
    Last Post: 10-08-2009, 06:31 PM
  2. XML Images
    By JavaWizz in forum XML
    Replies: 1
    Last Post: 10-17-2008, 10:19 AM
  3. images
    By amith in forum AWT / Swing
    Replies: 3
    Last Post: 06-27-2008, 08:38 PM
  4. images
    By amith in forum AWT / Swing
    Replies: 1
    Last Post: 05-20-2008, 10:54 AM
  5. Help with images...
    By toby in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 05:25 AM

Posting Permissions

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