Search code examples
javaeclipsefilejarmp3

Cannot read from an runnable Jar file


I'm trying to make a mp3 player and I used javazoom libraries. I save mp3 path in library.txt file to reopen them. There is not any problem with openning library.txt which is in the jar file.

Normally with eclipse program It is working well but when i created a jar file the problems begins. I can't use absolute paths to open any mp3 file with my jar file.

 File file = new File("/Users/orcungumus/Music/iTunes/iTunes Media/Music/Bruno Mars/Unorthodox Jukebox/1-16 16 Locked Out of Heaven.mp3");
        try {
            player.open(file);
        } catch (BasicPlayerException e1) {
            JOptionPane.showMessageDialog(null, e1.toString(),
                    "Error", JOptionPane.INFORMATION_MESSAGE);
        }

For making thinks easier to understand i used directly path of an file. It works for eclipse, but with jar file it can't open file.

This is the error which i take:

enter image description here

If it is important i use mac os.

Edit: I realized that this is not about absolute path by making mp3 path relative. Libraries give an error about audio format. So, the problem is still exist. what can be the differencies between runnable jar file version and eclipse run for an project.


Solution

  • well, that's hard to find out.

    now your problem is unable to open a audio file, which I can't handle.

    However you said that the programme run perfectly using eclipse, so the question became the different between running in eclipse and normal jar file.

    FIRST, eclipse not directly use java.exe nor javaw.exe for execution. Instead, eclipse use some custom defined library in order to redirect the console, handling exception, etc. (That is nothing to your problem)

    SECOND, eclipse will set the working directory for you automatically (to the project root directory), where may contain some necessary native library.

    THIRD, eclipse also define some path for native location for library, I think you may use eclipse built-in export to create the jar file which however not include the native library.

    the second and third difference may help you, because they are quite effective to jar file. I have just browsed javazoom briefly, I don't know whether there is native library. If not, I sorry that you have to find other solution.