I have packed all the class files and resources as a jar but on execution the sound files wont play. My package structure is:
+project
|_classes
|_ _*.class
This is my function for playing a looping sound file in jars, it works fine for me.
It appears that getResourceAsStream() doesn't work with jars. however, getResource() does.
public synchronized void alarm() {
try {
crit = AudioSystem.getClip();
AudioInputStream inputStream1 = AudioSystem.getAudioInputStream(this.getClass().getResource("critical.wav"));
crit.open(inputStream1);
crit.loop(Clip.LOOP_CONTINUOUSLY);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}