how to enable hot deploy in tomcat

后端 未结 4 1512
醉酒成梦
醉酒成梦 2020-12-03 09:06

I can write an ant script that copies updated class files to web-inf\\classes in tomcat. But how can I tell Tomcat 7.0 to auto pick up the changed class files f

相关标签:
4条回答
  • 2020-12-03 09:28

    Tomcat can only hot swap certain type of files such as JSP, and static files like JavaScript, CSS, etc. if you turn off cacheing but cannot hot swap Java classes, only restart the webapp. To achieve hot swapping Java classes, I’ve seen JRebel advertisement everywhere but have not tried their product.

    However, you could preserve Tomcat session by commenting out a directive as explained in the Tomcat documentation site: http://tomcat.apache.org/tomcat-7.0-doc/config/manager.html#Disable_Session_Persistence.

    Lastly, you could write ANT script to assemble WAR and redeploy every time the script is executed.

    Example build.xml:

    ...
    <target name="tomcat-stop">
        <exec executable="${server.home}/bin/catalina.bat">
            <arg value="stop"/>
        </exec>
    </target>
    
    <target name="tomcat-start">
        <exec executable="${server.home}/bin/startup.bat">
            <arg value="start"/>
        </exec>
    </target>
    ...
    <target name="all" depends="tomcat-stop,clean,init,compile,junit-slow,make_war,deploy,tomcat-start"></target>
    

    In any consolidation, I would avoid using Eclipse Tomcat Plugin for two reasons.

    1. In most version of Eclipse already include Tomcat as server adapter and comes with some options.
    2. Prevent IDE from bloating with plugins.
    0 讨论(0)
  • 2020-12-03 09:35

    I ended up using HotSwapAgent tool. That's a free alternative to JRebel

    0 讨论(0)
  • 2020-12-03 09:35

    There is a new plugin for intellij that supports it: https://plugins.jetbrains.com/plugin/9492-smart-tomcat

    0 讨论(0)
  • 2020-12-03 09:49

    Apparently another option is to use jetty (for instance, while doing development) it has ability to do hot swapping on the fly more easily.

    0 讨论(0)
提交回复
热议问题