Question:
Using Tomcat HotSwap with classes and resources (.jsp, .css, .js, etc.) works fine in this case, but when I update any configuration file in my application (.properties file), HotSwap does not work, and the changes are not applied to the Tomcat deployment.
So, is there any way to HotSwap application configuration files, as is done with classes and resources (.jsp, .css, .js, etc.)?
Answer:
Please enable the File | Settings | Tools | Actions on Save | Build project , also check the menu File | Settings | Build, Execution, Deployment | Compiler | Build project automatically) and File | Settings | Advanced Settings | Allow auto-make to start even if developed application is currently running.
Then, in the main menu, go to Run | Edit Configurations.
- Open the application server run configuration.
- Configure the following options on the Server tab:
- On 'Update' action: Select "Update classes and resources".
- On frame deactivation: Select "Update classes and resources", this will be triggered when you switch from IntelliJ IDEA to a different application (for example, to a web browser).
- On the Deployment tab, please choose the exploded war file if available.
Fig 1: Server tab settings
Fig 2: Deployment tab settings
Finally, please run the Tomcat application with Debug mode, then change some properties file, then the corresponding deployed resource should be updated once you swith your window to the web browser(means the IDEA lost focus).
Note: These settings might not 100% work. Since not all applications can load the new property file contents, if some framework or library has cached these values instead of dynamically loading them, this will not work.
Tested source code like below:
JSP file:
<%
InputStream inputStream = application.getResourceAsStream("/WEB-INF/hello.properties");
String content = inputStream != null ? new String(inputStream.readAllBytes()) : "";
%>
<%=content%>
Servlet file:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
InputStream inputStream = getServletContext().getResourceAsStream("/WEB-INF/classes/hello.properties");
String content = inputStream != null ? new String(inputStream.readAllBytes()) : "";
// Hello
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h1>" + message + "</h1>");
out.println("<pre> abc " + content + "</pre>");
out.println("</body></html>");
}
https://www.jetbrains.com/idea/help/updating-applications-on-application-servers.html
Comments
0 comments
Please sign in to leave a comment.