Results 1 to 14 of 14
  1. #1
    dko
    dko is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default Finds resource in netbeans but the jar does not

    Hi again. After the help I received earlier I was able to figure out how to grab data from a resource file and I got things to work... or so I thought.
    I have the IDE netbeans, and my code there works fine, loading the resources I request. But when I do a clean compile and try to run the separate jar file, it doesn't find the resources.
    Could someone take a look at and example of my code and tell me what might be wrong?
    Java Code:
    String fName = "resources/data/text_" + language + ".properties";
            String resFName = fName.substring(resDir.length()- 1);
    
            
            //resource data for the screen
            InputStream is = getClass().getResourceAsStream(resFName);
            InputStreamReader isr;
    
            if (is != null)
                isr = new InputStreamReader(is);
            else
                isr = null;

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

  3. #3
    dko
    dko is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default

    Yes, I have all the files included under a package folder and they appear in the Jar when I open it with a zipping utility.

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

    Default

    Where are the images located in relationship to the class files? Can you post an image of the jar's directory structure?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    Also your code should print out the value of resFName to be sure it matches the path to the file.

  6. #6
    dko
    dko is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default

    Here is a pic of my jar's directory structure (At least from the root) and I have done the printing of resFName when I was testing the code thru netBeans. Like in this example I got /data/text_en.properties, which seems like the correct directory.
    Finds resource in netbeans but the jar does not-jarcontents.jpg

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    try changing resFName by removing the leading /.

    Try opening the jar file in a utility that shows the all contents vs just the root.

    See attached
    Attached Thumbnails Attached Thumbnails Finds resource in netbeans but the jar does not-jarentries.jpg  
    Last edited by Norm; 05-27-2011 at 03:42 AM.

  8. #8
    dko
    dko is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default

    Nope didn't help. If I do that, running my code in netBeans can't find the resources anymore and the jar still can't find them. And I'm making sure to re build every time just in case.
    Not sure if it will be any help, but I want to cover my bases and include a pic of projects window so you can see how I have my resources folders set up.
    Finds resource in netbeans but the jar does not-resourcesinnetbeans.png

    EDIT: Also another of my directory structure as requested.Finds resource in netbeans but the jar does not-directorystruct.jpg
    Last edited by dko; 05-27-2011 at 04:31 AM.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default

    What does the filename you use in getResource actually look like?
    Is it "/data/text_<something>.properties" or what?

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    The image of ???(the jar file contents) is unreadable. Too small.

  11. #11
    dko
    dko is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default

    Ok I think the site shrank it, so here is a link to a copy I put in my photobucket.
    Also in this one instance the file name is text_en.properties. But it's not the only thing I'm trying to load. What code I've posted is just and example of what I have been doing

    http://img.photobucket.com/albums/v143/ssDko/take2.png
    Last edited by dko; 05-27-2011 at 08:05 PM.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    I don't know if getResourceAsStream is case sensitive. Your filenames begin with different case.

    Otherwise write a very small program to demo the problem and try all the combinations that are possible until you find the one that works. If you want others to assist, post/attach the jar file with the test file both source .java and .class files.

  13. #13
    dko
    dko is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default

    I think I have solved it. Thanks for the help

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    Can you tell us what the problem was and how you fixed it so the next one with the same problem will know what to do?

Similar Threads

  1. closing the use of a resource
    By jayragz in forum New To Java
    Replies: 14
    Last Post: 05-17-2011, 04:24 PM
  2. JAVA resource(s)
    By Sparky in forum New To Java
    Replies: 4
    Last Post: 02-15-2011, 01:26 AM
  3. Resource File
    By dvlchd3 in forum Eclipse
    Replies: 2
    Last Post: 01-13-2010, 10:32 AM
  4. The requested resource is not available.
    By ravichandra.t in forum Java Servlet
    Replies: 0
    Last Post: 07-29-2009, 02:18 PM
  5. P2P resource sharing
    By vishal.babar07@gmail.com in forum Advanced Java
    Replies: 0
    Last Post: 02-12-2009, 02:48 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
  •