title: How can a Java application play a sound clip?
body: <p>The following is a link to the most likely explanation I've seen, but I still have questions.</p>
  
  <p><a href="https://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java/26318#26318">How can I play sound in Java?</a></p>
  
  <p>I'll quote the code here:</p>
  
  <pre><code>public static synchronized void playSound(final String url) {
  new Thread(new Runnable() {
    public void run() {
      try {
        Clip clip = AudioSystem.getClip();
        AudioInputStream inputStream = AudioSystem.getAudioInputStream(Main.class.getResourceAsStream("/path/to/sounds/" + url));
        clip.open(inputStream);
        clip.start(); 
      } catch (Exception e) {
        System.err.println(e.getMessage());
      }
    }
  }).start();
  </code></pre>
  
  <p>}</p>
  
  <ol>
  <li>Does this work in an application, as opposed to an Applet?</li>
  <li>The method Main.class.getResourceAsStream() seems to require <strong>import com.sun.tools.apt.Main;</strong> but I cannot find documentation for that, and I don't know what it does.  For instance, is "/path/to/sounds/" absolute, or relative, and if the latter, relative to where?</li>
  </ol>
  
  <p>I've spent many hours now trying to play a simple sound effect.  It's unbelievable how difficult it is.  I hope that the above code can be made to work.  Thanks for any help.</p>
  
  <p>Chap</p>