Tomcat(嵌入式),无需重启即可进行更改

时间:2018-04-08 18:36:49

标签: java tomcat refresh

如何刷新静态文件,如TomCat中的html / css(嵌入式)?无需重启服务器。 InelliJ Idea。通过使用某种配置

public class TomStart {
    public static void main(String[] args) throws LifecycleException,
            InterruptedException, ServletException {

        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8082);
        tomcat.addContext("/", "/web");
        Context ctx = tomcat.addContext("/", new File(".").getAbsolutePath());

        Tomcat.addServlet(ctx, "Embedded", new HttpServlet() {
            @Override
            protected void service(HttpServletRequest req, HttpServletResponse resp)
                    throws ServletException, IOException {

                Writer w = resp.getWriter();
                w.write("Embedded Tomcat servlet.\n");
                w.flush();
                w.close();
            }
        });

        ctx.addServletMappingDecoded("/*", "Embedded");

        tomcat.start();
        tomcat.getServer().await();
    }

}