No sound after export to jar

audio, eclipse, embedded-resource, java

Solution

The problem is in this

AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("sound.wav"));

in JAR file isn't working `getResourceAsStream` for any reason. So I replace it with `getResource`:

AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResource("sound.wav"));

and this works fine.

Problem

I have problem with my app. When I run app in Eclipse, sound played well, but if I export app to runnable jar, sound doesn't work. Method, where sound is played: ``` public static synchronized void playSound() { new Thread(new Runnable() { // The wrapper thread is unnecessary, unless it blocks on the // Clip finishing; see comments. public void run() { try { Clip clip = AudioSystem.getClip(); AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("sound.wav")); clip = AudioSystem.getClip(); clip.open(inputStream); clip.start(); } catch (Exception e) { System.err.println(e.getMessage()); } } }).start(); } ``` Where can be a mistake?

Original source