Pregunta

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?

¿Fue útil?

Solución

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

Otros consejos

If the ini file is located in the jar archive, read it like this :

inputstream = getClass()
          .getClassLoader()
          .getResourceAsStream("settings/settings.ini");

Else if it's located outside of your jar archive, you should move or copy your ini file in ./settings/settings.ini (relatively to the current working directory of your application).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top