none of the answers I found to this question worked, so I have to ask here: I'm using Eclipse and I have a program that I export as a runnable jar, and it plays an audio, but the audio has to be in the same folder as the exported jar file or else it doesn't play. How can I package it into the runnable jar so that it doesn't need the audio to actually be there? PS: I'm doing things the old-fashioned way so not using a build system (Maven or Gradle) this is my code; it plays an audio file when a button is pressed:
AudioFormat audioformat = null;
DataLine.Info info = new DataLine.Info(Clip.class, audioformat);
try {
Clip audioclip = (Clip) AudioSystem.getLine(info);
File audio1 = new File("audiofile.wav");
AudioInputStream audiostream = AudioSystem.getAudioInputStream(audio1);
audioformat = audiostream.getFormat();
audioclip.open(audiostream);
audioclip.start();
audiostream.close();
} catch (LineUnavailableException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UnsupportedAudioFileException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
```