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:
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:
Obviously this path doesn't exist, because the file is inside a Jar....How do I solve this problem? =/
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.
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.
So there is no easy way to convert:
To pulling in the resource from the Jar? Any examples out there of pulling a Resource from a Jar like this?
File test = new File("sounds"+File.separator+"incim.wav");
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.
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:
In my jar there is:
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.
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.
I'm pretty much clueless myself. I'd love to show you what I got if you are interested.
"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:
Thanks for the patience.
Cool. We both learned something here.
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.