title: Short sound file plays in Netbeans, but not in jar
body: <p>I am working on a lottery program that updates a list of names in a loop using varying intervals. For each update I want to play a short (300 ms) click.wav. When I run the program in Netbeans, everything works perfectly, but when I build the jar, it refuses to play. The weird thing is that if I lengthen the sound to a few seconds by adding silence at the end, it plays, but then the timing is all off, and it only starts playing after the loop has run 4-5 times.</p>
  
  <p>I'm using thread.sleep() to initiate a pause between loops. While this may not be the best way to do it, it certainly is the easiest, and it doesn't matter for the scope of this program. I've tried using a timer, but the sound still wouldn't play.</p>
  
  <p>This is my code to play the wav file.</p>
  
  <pre><code>private static void play(String filename) {
      URL url = VinLotteri.class.getResource(filename);
      try {
          Clip clip = AudioSystem.getClip();
          clip.open(AudioSystem.getAudioInputStream(url));
          clip.start();
      } catch (LineUnavailableException | UnsupportedAudioFileException | IOException fail) {
      }
  }
  </code></pre>
  
  <p>And here's the loop code. Please ignore (or give constructive criticism) any bad code not related to the problem. I've only been programming for a few months, so there's probably a lot of that.</p>
  
  <pre><code>class StartTrekning extends SwingWorker&lt;String, String&gt; {
  
      private StartTrekning(List&lt;String&gt; navn, String vinner) {
      }
  
      @Override
      protected String doInBackground() {
          firstDraw = false;
          Random rnd = new Random();
          int v = 0;
          int vinnerID = -1;
          isRunning = true;
          int counterPluss = 0;
          int counterMinus = 0;
  
          int rand = rnd.nextInt(17) + 45; // Antall trekninger 45-61 
          //Setter opp ulik pause mellom hver trekning
          for (int i = rand; i &gt; 0; i--) {
              if (i &gt; 40) {
                  v = 100;
              } else if (i &gt; 35) {
                  v = 150;
              } else if (i &gt; 25) {
                  v = 200;
              } else if (i &gt; 20) {
                  v = 250;
              } else if (i &gt; 15) {
                  v = 300;
              } else if (i &gt; 10) {
                  v = 400;
              } else if (i &gt; 6) {
                  v = 550;
              } else if (i &gt; 3) {
                  v = 800;
              } else if (i &gt; 1) {
                  v = 1200;
              } else if (i &gt; 0 &amp;&amp; rand &gt; 53) {
                  v = 2000;
              }
  
              play(click);
              vinnerID++;//Øker vinnerID, som gir index for navnelisten navn
  
              //"Loop-kode" (starter listen på nytt når den når slutten)
              if (vinnerID &gt; navn.size() - 1) {
                  vinnerID = 0;
              }
              vinner = navn.get(vinnerID);
              int pluss10 = vinnerID;
              int pluss9 = vinnerID;
              int pluss8 = vinnerID;
              int pluss7 = vinnerID;
              int pluss6 = vinnerID;
              int pluss5 = vinnerID;
              int pluss4 = vinnerID;
              int pluss3 = vinnerID;
              int pluss2 = vinnerID;
              int pluss1 = vinnerID;
              int minus1 = vinnerID;
              int minus2 = vinnerID;
              int minus3 = vinnerID;
  
              if (vinnerID &gt; navn.size() - 11) {
                  pluss10 = -10 + counterPluss;
              }
              if (vinnerID &gt; navn.size() - 10) {
                  pluss9 = -10 + counterPluss;
              }
              if (vinnerID &gt; navn.size() - 9) {
                  pluss8 = -10 + counterPluss;
              }
              if (vinnerID &gt; navn.size() - 8) {
                  pluss7 = -10 + counterPluss;
              }
              if (vinnerID &gt; navn.size() - 7) {
                  pluss6 = -10 + counterPluss;
              }
              if (vinnerID &gt; navn.size() - 6) {
                  pluss5 = -10 + counterPluss;
              }
              if (vinnerID &gt; navn.size() - 5) {
                  pluss4 = -10 + counterPluss;
              }
              if (vinnerID &gt; navn.size() - 4) {
                  pluss3 = -10 + counterPluss;
              }
              if (vinnerID &gt; navn.size() - 3) {
                  pluss2 = -10 + counterPluss;
              }
              if (vinnerID &gt; navn.size() - 2) {
                  pluss1 = -10 + counterPluss;
                  counterPluss = 0;
              }
              if (vinnerID &lt; 3) {
                  minus3 = navn.size() + counterMinus;
              }
              if (vinnerID &lt; 2) {
                  minus2 = navn.size() + counterMinus;
              }
              if (vinnerID &lt; 1) {
                  minus1 = navn.size() + counterMinus;
              }
              if (vinnerID &lt; 3) {
                  counterMinus++;
              }
              if (vinnerID == 3) {
                  counterMinus = 0;
              }
              if (vinnerID &gt; navn.size() - 11) {
                  counterPluss++;
              }
              //Slutt på "loop-kode"
  
              // Lager "rulleteksten"
              lblVinner.setText(vinner);
              lblHighlight1.setText(navn.get(minus1 - 1));
              lblHighlight2.setText(navn.get(minus2 - 2));
              lblHighlight3.setText(navn.get(minus3 - 3));
              lblHighlight7.setText(navn.get(pluss1 + 1));
              lblHighlight8.setText(navn.get(pluss2 + 2));
              lblHighlight9.setText(navn.get(pluss3 + 3));
              lblHighlight10.setText(navn.get(pluss4 + 4));
              lblHighlight11.setText(navn.get(pluss5 + 5));
              lblHighlight12.setText(navn.get(pluss6 + 6));
              lblHighlight13.setText(navn.get(pluss7 + 7));
              lblHighlight4.setText(navn.get(pluss8 + 8));
              lblHighlight5.setText(navn.get(pluss9 + 9));
              lblHighlight6.setText(navn.get(pluss10 + 10));
              try {
                  Thread.sleep(v);
              } catch (InterruptedException ex) {
                  Logger.getLogger(VinLotteri.class.getName()).log(Level.SEVERE, null, ex);
              }      
          }
  
          int rand1 = rnd.nextInt(100);
          //Legger inn en liten kunstpause
          if (rand1 &lt; 50) {
              try {
                  Thread.sleep(v);
              } catch (InterruptedException ex) {
                  Logger.getLogger(VinLotteri.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
          panelVinner.append(idVinn + ". Trekning: " + vinner + "\n"); //Skriver ut vinneren
          play(fanfare);
          flashText(lblVinner, Color.WHITE, Color.BLUE, 270, 1650);
          vinnere.add(vinner); //Lager vinnerliste
          idVinn++;
          nyListe(vinnerID, vinner);
          isRunning = false;
          return null;
      }
  </code></pre>
  
  <p>Any help would be greatly appreciated. Thank you.</p>