Results 1 to 6 of 6
  1. #1
    IamKira is offline Member
    Join Date
    Jul 2009
    Posts
    11
    Rep Power
    0

    Default Adding folders to a Jar

    Hello,

    I have an application that uses images stored in the folder "images" that is at the root of the project. I want to export my application into a jar file and I want that jar file to contain the images folder within it. How to do this using Netbeans IDE?
    Also how should I declare my Image objects? Right now I am doing this :

    Image img = Toolkit.getDefaultToolkit().getImage("images/" + fileName);

    But apperantly this code won't work if the images are to be read from within a Jar. I am looking for the correct way to do it.

    Thanks in advance.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    Stick the images folder under Source Packages in your Netbeans project and use getResourceAsStream() to get a stream to that resource as an InputStream. I can never remember whether the path has to start with a "/" or not...I always end up having to experiment!

  3. #3
    IamKira is offline Member
    Join Date
    Jul 2009
    Posts
    11
    Rep Power
    0

    Default

    Hello, can you tell me what's wrong here?


  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    Your url is null, implying that that path isn't correct.
    Try it with a '/' at the start.

  5. #5
    IamKira is offline Member
    Join Date
    Jul 2009
    Posts
    11
    Rep Power
    0

    Default

    you're right thanks.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    As I say, I can never remember whether it needs a '/' or not...:)

Similar Threads

  1. Replies: 4
    Last Post: 10-10-2009, 12:26 AM
  2. Lots of my folders have become read-only
    By Manoeuvre in forum Eclipse
    Replies: 5
    Last Post: 12-02-2008, 12:48 PM
  3. Folders instead of packages after OS crashed
    By Kubuntek in forum Eclipse
    Replies: 0
    Last Post: 08-03-2008, 02:26 PM
  4. Replies: 2
    Last Post: 11-27-2007, 01:45 PM
  5. URGENTTT...zip folders in java
    By rach in forum New To Java
    Replies: 3
    Last Post: 08-13-2007, 03:55 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
  •