You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to specify a default config file in my resources-folder using FileConfig.builder(configPath).defaultResource(default), but the resource won't be found, as the FileNotFoundAction points to the night-config's JAR:
I'd suggest return copyData(Thread.currentThread().getContextClassLoader().getResource(resourcePath)); to replace this line. This resolves correctly to the resources directory (.../build/resources/main/).
The text was updated successfully, but these errors were encountered:
Thanks for reporting!
You could use FileConfigBuilder#defaultData, or onFileNotFound with copyData + getResource on your class or classloader, so that is resolves properly.
edit: after some testing, it seems that it works fine when the resource path is absolute (e.g. /resource.json). Relative paths, however, do not work, but IMO they've always been a bit fragile to work with 😄
A note about the getContextClassLoader: I'm reluctant to use it, because it's more like an artifact of the past than a proper way to get "the right" classloader. Also, it may not exist in some environments.
The best solution is to pass an absolute path to your resource, or to call YourClass.class.getResource yourself. See Class#getResource.
The docs and wiki should be updated to reflect this.
Hi,
thanks for this library!
I wanted to specify a default config file in my resources-folder using
FileConfig.builder(configPath).defaultResource(default)
, but the resource won't be found, as the FileNotFoundAction points to the night-config's JAR:night-config/core/src/main/java/com/electronwill/nightconfig/core/file/FileNotFoundAction.java
Line 106 in 4ac1b3c
FileNotFoundAction.class.getResource("") = jar:file:/C:/Users/[...]/.gradle/caches/[...]/com.electronwill.night-config/core/3.6.6/[...]/core-3.6.6.jar!/com/electronwill/nightconfig/core/file/
I'd suggest
return copyData(Thread.currentThread().getContextClassLoader().getResource(resourcePath));
to replace this line. This resolves correctly to the resources directory (.../build/resources/main/
).The text was updated successfully, but these errors were encountered: