title: how to get classpath from mp3 within a jar file
body: <p>I've got a problem with my classpath within a jar file. With pictures<br/>
  <code>getClass().getResource("picture.png")</code> works fine. But I need to get a mp3 file.<br/>
  If I put in the whole path outside of the jar file it works just fine, however if i try it<br/> without the full path like <code>getClass().getResource("picture.png")</code> it says "File not Found".
  So I'm looking for a solution for the path of song.mp3 so that if I build the .jar and open it on a different computer the song still plays.</p>
  
  <p>this is my code:<br/></p>
  
  <pre><code>package bgmusic;
  
  import java.io.*;
  
  import javax.media.Format;
  import javax.media.Manager;
  import javax.media.MediaLocator;
  import javax.media.Player;
  import javax.media.PlugInManager;
  import javax.media.format.AudioFormat;
  
  public class Bgmusic {
      public static void main(String[] args) {
          Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
          Format input2 = new AudioFormat(AudioFormat.MPEG);
          Format output = new AudioFormat(AudioFormat.LINEAR);
          PlugInManager.addPlugIn(
              "com.sun.media.codec.audio.mp3.JavaDecoder",
              new Format[]{input1, input2},
              new Format[]{output},
              PlugInManager.CODEC
          );
          try{
              Player player = Manager.createPlayer(new MediaLocator(new File("song.mp3").toURI().toURL()));
              player.start();
          }
          catch(Exception ex){
              ex.printStackTrace();
          }
      }
  }
  </code></pre>