When packaging the Spring Boot application as a single jar, all the dependency jars are also contained in that jar file. It forms a hierarchical structure of jars. How can I access to the resource file(such as a xml) that built in one of the dependency jar without unpackaging them?
Asked
Active
Viewed 1,849 times
1 Answers
-1
If dependency jar is in your classpath, you can read XML files like:
URL loadedResource = this.getClass().getClassLoader().getResource(“your.xml”);
InputStream inputStream = loadedResource.openStream();
OR
Resource resource=new CLassPathResource(“your.xml”);
resource.getInputStream();
Follow this stackoverfow thread
If it is properties file you want to read, you can use @PropertySource annotation:
@PropertySource("classpath:your.properties")

Yogi
- 1,805
- 13
- 24