Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HereThereBeMonsters opened this issue Sep 1, 2017 · 1 comment

Comments

@HereThereBeMonsters
Copy link

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 ?

@colesico
Copy link

colesico commented Jan 28, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants