Results 1 to 7 of 7
  1. #1
    verd is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Loading images/resources from a jar.

    Well, I've seen many many forums on this, but my situation is different here's my source tree:
    -Client
    --src
    ---core(Current)
    ---imgs

    Jar tree:
    -The jar
    --core
    --imgs

    Java Code:
    ChatInterfaceImage = ImageIO.read(new File("imgs/ChatInterface.png"));
    This only works without it being packed in a jar.

    Note:I'm trying to load this image from a different package within the jar.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Loading images/resources from a jar.

    "imgs/ChatInterface.png" is a relative path. "/imgs/ChatInterface.png" would be an absolute path.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    verd is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: Loading images/resources from a jar.

    Ok, but this still does not work with a jar.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Loading images/resources from a jar.

    What happens if you use "../imgs/ChatInterface.png"?

    But most important, don't get the image as a File but rather as as resource! This is very, very important!

  5. #5
    verd is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: Loading images/resources from a jar.

    Didn't even notice i was making a new file, it wont let me getresource

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Loading images/resources from a jar.

    Quote Originally Posted by verd View Post
    Didn't even notice i was making a new file, it wont let me getresource
    "it wont let me getresource" doesn't give us enough information to tell us what you may be doing wrong or how to fix it. How are you trying to get the resource? Can you show us the code? Is it being done from within a static or non-static context? What exact error message are you seeing?

  7. #7
    verd is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: Loading images/resources from a jar.

    I got it moved the imgs into core, and made a loader class.

Similar Threads

  1. loading resources in an applet
    By Gatts79 in forum Java Applets
    Replies: 5
    Last Post: 03-06-2009, 02:19 PM
  2. Protocol for loading resources from jar
    By SamSam in forum Advanced Java
    Replies: 2
    Last Post: 02-12-2009, 07:14 PM
  3. Already import the resources but images are missing
    By Java.child in forum New To Java
    Replies: 5
    Last Post: 09-05-2008, 05:09 PM
  4. Loading resources generates warning messages
    By Namita Patil in forum New To Java
    Replies: 6
    Last Post: 07-03-2008, 02:04 PM
  5. Problem loading resources.
    By jimm1 in forum Advanced Java
    Replies: 6
    Last Post: 06-23-2008, 07:31 PM

Posting Permissions

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