cfg4j / cfg4j

Modern configuration library for distributed apps written in Java.

Home Page:http://cfg4j.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use of ClasspathConfigurationSource inside JAR in Windows fails if file not at root

HereThereBeMonsters opened this issue · comments

Using cfg4j in a client app (JavaFX and Swing).

I have a ClasspathConfigurationSource in which I add a path "/config/application.properties".

When I start the program from the IDE, everything is fine. But when I build the app JAR and launch the JAR, I get an exception:

java.lang.IllegalStateException: Can't bind method lookAndFeel

The exception happens in ClasspathConfigurationSource at line 122. The root of the problem seems to be that the java.nio.Path API generates path strings with backslashes when running in Windows (the concrete class of the Path objects is WindowsPath). Which is fine for actual files on the FS, but not fine for:

getClass().getClassLoader().getResourceAsStream(path.toString())

Which then returns null.

My workaround for now will be to place the config file at the root of the classpath, avoiding the problem.

I am not sure what the proper fix should be. Maybe if getResourceAsStream returns null, retry after converting all backslashes to forward slashes ?

I have the same problem. The original ClasspathConfigurationSource has seems buggy.
I locally fixed that with my own ClasspathConfigurationSource impl that replace windows backslashas to unix slashas.