Ibrahim R Serpici
Ibrahim R Serpici

Reputation: 1076

Jar File Missing File Path

Everything works fine while my ide is open, but when i build my project it's not working as jar file. I guess the problem is at the path of my resource, I can't find any way to handle this problem, please help me if you have any solution.

public void playSound(String filename){

        String strFilename = filename;

        try {
            ClassLoader classLoader = getClass().getClassLoader();
            soundFile = new File(classLoader.getResource(strFilename).getFile());
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }

Upvotes: 0

Views: 123

Answers (1)

Brett Okken
Brett Okken

Reputation: 6306

You cannot address a resource in your jar as a File. In your IDE it likely is a file in the file system, not a resource in a jar. You need to be able to read the content as a URL and/or InputStream.

Upvotes: 1

Related Questions