Results 1 to 11 of 11
  1. #1
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default Jar File Problem

    Ok so I have a feeling the answer to this question lies within the Manifest file, which I do not fully understand.

    Here is the problem:

    Java Code:
    		stream[0]=AudioSystem.getAudioInputStream(new File("sounds"+File.separator+"incim.wav"));
    The above is a line of code that loads a wav file from the sounds folder located in the same directory. Now when I want to make this a Jar executable, I use Eclipse and Export it as a Jar. The Jar file contains the sounds folder, but I get NullPointerException when one of the sounds is suppose to play. Printing out the absolute path I find:

    C:/Something/Something/Sounds/file.wav

    Obviously this path doesn't exist, because the file is inside a Jar....How do I solve this problem? =/

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

    Default

    AFAIK there are no "files" inside of a Jar but instead there are resources. Have you tried getting the data as a resource? The Sun Jar tutorial goes over this I believe.

  3. #3
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default

    No I haven't checked into that. I'll need to see if I have to re-work the entire way I load the sound files.

  4. #4
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default

    So there is no easy way to convert:

    Java Code:
    File test = new File("sounds"+File.separator+"incim.wav");
    To pulling in the resource from the Jar? Any examples out there of pulling a Resource from a Jar like this?

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

    Default

    There are tons of examples of extracting resources of different types in the tutorials. Again, I strongly suggest that you peruse them as they will help.

  6. #6
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default

    I've looked over as many examples as I can. And they all seem pretty straight forward and easy. The only thing I see different is they use:
    Java Code:
    this.getClass().getResourceAsStream("sounds"+File.separator+"incim.wav")
    In my jar there is:
    /sounds/incim.wav
    class1.class
    class2.class
    class3.class

    etc.

    So as far as I know, I should be grabbing the resource correctly. On my mac it seems to work fine, but when I take the Jar to a windows machine it bugs out on me with a null pointer. I understand windows is case sensitive, and as far as I can tell the files are exact same. Also Windows uses \ instead of /, but I'm fairly certain File.separator takes care of that for me.

    Any suggestions?
    Last edited by Moncleared; 10-18-2009 at 04:39 AM.

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

    Default

    Hm, don't know. The use of File.separator seems questionable to me in this situation as there are no files inside of a Jar. I recommend that you simply use "/" instead, though I have no idea if this will solve your problem.

  8. #8
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default

    I'm pretty much clueless myself. I'd love to show you what I got if you are interested.

  9. #9
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default

    "The name of a resource is independent of the Java implementation; in particular, the path separator is always a slash (/). However, the Java implementation controls the details of how the contents of the resource are mapped into a file, database, or other object containing the actual resource."

    ---Good call yet again, when using a resource there is no system dependant separator, java will always use "/", which is why my Mac (separator is "/") worked fine, but the windows box using "\" bugged out.

    So for anyone trying to use this properly:

    Java Code:
    this.getClass().getResourceAsStream("sounds/incim.wav")
    Thanks for the patience.

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

  11. #11
    gcampton Guest

    Default

    all Unix systems use "/" (max, linux, bsd, solaris). Unfortuantely windows uses "\" just to be a pain in the butt, and seem different.
    I always wondered how java especially would be portable in situations such as this... claiming to be so portable.

Similar Threads

  1. jar file problem
    By nishant.4545 in forum New To Java
    Replies: 1
    Last Post: 07-03-2009, 08:36 PM
  2. problem with jar file
    By biba84 in forum Advanced Java
    Replies: 7
    Last Post: 11-09-2008, 06:46 PM
  3. problem - using a jar file
    By jon80 in forum New To Java
    Replies: 6
    Last Post: 07-07-2008, 07:49 AM
  4. problem with jar file pls help
    By jinu5 in forum New To Java
    Replies: 0
    Last Post: 08-15-2007, 10:41 PM
  5. Problem in batch file
    By marwa in forum New To Java
    Replies: 0
    Last Post: 08-14-2007, 10:24 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
  •