admin管理员组文章数量:1123376
I have a use case where I need to refer to configuration files from various nested JARs within a Spring Boot fat JAR
public void searchConfFiles() throws Exception {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// Search for all .conf files in the nested JARs
Resource[] resources = resolver.getResources("classpath:/BOOT-INF/lib/**/*.conf");
System.out.println("resoucre length"+resources.length);
for (Resource resource : resources) {
if (resource.exists()) {
try (InputStream inputStream = resource.getInputStream()) {
String content = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
System.out.println("Found .conf file: " + resource.getURI());
System.out.println(content);
}
}
}
}
It is displaying a resource length of 0, even though the .conf files are included. The approach should work when running the application using the jar command, gradlew bootRun, or the maven command.
Does Spring provide a solution for this ?
Any other alternatives ?
I have a use case where I need to refer to configuration files from various nested JARs within a Spring Boot fat JAR
public void searchConfFiles() throws Exception {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// Search for all .conf files in the nested JARs
Resource[] resources = resolver.getResources("classpath:/BOOT-INF/lib/**/*.conf");
System.out.println("resoucre length"+resources.length);
for (Resource resource : resources) {
if (resource.exists()) {
try (InputStream inputStream = resource.getInputStream()) {
String content = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
System.out.println("Found .conf file: " + resource.getURI());
System.out.println(content);
}
}
}
}
It is displaying a resource length of 0, even though the .conf files are included. The approach should work when running the application using the jar command, gradlew bootRun, or the maven command.
Does Spring provide a solution for this ?
Any other alternatives ?
Share Improve this question asked 13 hours ago Deepu VarmaDeepu Varma 214 bronze badges1 Answer
Reset to default 1Those jars are in classpath so you can use resolver.getResources("classpath:/*.conf")
.
本文标签: javaReading files from Resources folder of a Nested jars of a spring boot JarStack Overflow
版权声明:本文标题:java - Reading files from Resources folder of a Nested jars of a spring boot Jar - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736566106a1944706.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论