2

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?

xiangyq000
  • 111
  • 1
  • 2
  • 5

1 Answers1

-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