Search code examples
javaeclipsejarembedded-resourcenosuchfileexception

NoSuchFileException in .jar but not in Eclipse


When i compile and run my program in Eclipse, is runs without exceptions. But when i export it to an runnable jar or an normal jar it does not find my settings file.

My path is:

String path= "src/settings/settings.ini";

In eclipse it runs without exception, but in a jar, it throws the exception immediately .

How is it possible to make the jar just work as it is in eclipse?


Solution

  • while inside jar the file is no more physical file, so you may need to read it as Stream

    getClassLoader().getResourceAsStream("settings/settings.ini");
    

    considering that settings.ini is under classpath (runtime) at specified path