I have the following code in a static method:
clips.open(AudioSystem.getAudioInputStream(Sound.class.getResourceAsStream("folder/sound.wav")));
Also, folder
is in the same directory as Sound.java
. When I run the program in Eclipse, the sound is played. However, when I export the file to a JAR file, the sound no longer plays.
If I change getResourceAsStream()
to getResource()
, both Eclipse and the JAR file play the sound. Why does this happen? I have read around and many people suggest that getResourceAsStream()
simply doesn't work in JAR files. Is this the case, and if so, why not?