Best practices to store and access resource files in java web application

前端 未结 1 1221
不知归路
不知归路 2021-01-02 13:22

I have a bunch of text, xml and other files (i.e. resources) that I need to access using servlets in java web app. For example, there is an xml file, a part of which is retu

相关标签:
1条回答
  • 2021-01-02 13:57

    It's perfectly fine to load static resources using the classloader. That's what ResourceBundle does to load the internationalized properties files for example.

    Put them in WEB-INF/classes along with your class files, or in a jar inside WEB-INF/lib, and load them with the ClassLoader as indicated by the answers you already read.

    That doesn't forbid you to place these files in a separate directory from the Java source files in your project. The build process should just make sure to put them in the appropriate location for runtime. The Maven and Gradle convention is to put the source files under src/main/java and the resource files under src/main/resources.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题