2

I have a program with war file sounds. The sounds are playing perfectly when I ran the program in eclipse but in the jar file, I get a FileNotFoundException. This is how I added the war files:

public class MainClass implements Serializable{

    private static final long serialVersionUID = 1L;
    public static Library library;
    
    public static void main(String[] args)
    {
        try {
            loading();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        
        if(library == null) {
            library = Library.getInstance();
        }
        
        try
        {
            FileInputStream button4 = new FileInputStream("sound/welcome.wav");
            AudioStream b4 = new AudioStream(button4);
            AudioPlayer.player.start(b4);
        }
        catch(FileNotFoundException e)
        {
            JOptionPane.showMessageDialog(null,"File not found");
        }
        catch(IOException eio)
        {
            JOptionPane.showMessageDialog(null,"Sound Problems");
        }
        Login login = new Login();
        login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        login.setVisible(true);
        login.setSize(600, 400);
    }
}

The war file is in the same folder as my project. Do I need to add the file in different way? Here is how the war file is located in the project:

enter image description here

Cena
  • 3,316
  • 2
  • 17
  • 34
Daniel16
  • 113
  • 8

1 Answers1

1

"File paths" from a war-context are different from paths in your IDE and using FileInputStream in this way does not work.

See File path to resource in our war/WEB-INF folder? for hints on how to load a resource from within a war/servlet context.

Martin
  • 126
  • 1
  • 5