how to enable hot deploy in tomcat
Asked Answered
T

5

9

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 from web-inf/classes directory?

I tried setting autoDeploy="true" in tomcat Host configuration server.xml but when a change is detected, Tomcat session is destroyed. Can I easily a substitute eclipse tomcat plugin in Intellij

Tittivate answered 8/9, 2015 at 13:24 Comment(1)
T
13

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

Tittivate answered 10/9, 2015 at 19:32 Comment(0)
M
7

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.
Multinational answered 9/9, 2015 at 14:49 Comment(2)
thank you, I have a similar script. I was wondering how its done in eclipse with eclipse tomcat plugin. Its supporting hot deploy in tomcat without session destroyTittivate
Eclipse lets you do hot swap in tomcat for free, as opposed to JRebel. I wonder how it does it, because I would like to do the same thing in IntellijTittivate
T
1

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

Tittivate answered 10/12, 2018 at 17:41 Comment(1)
How to enable hot deployment in the smart tomcat plugin? I could not find the solution in the mentioned url.Ashcraft
C
0

Another solution is the Maven plugin Manik-Hot-Depoy. This is an open source plugin independent form the application or web server. It supports autdeploy as also hotdeploy and can be configured in the pom.xml.

Web applications are deployed in tomcat under the $CATALINA_HOME\webapps directory.

Here is an example:

 <!-- Manik Hotdploy -->
      <plugin>
        <groupId>org.imixs.maven</groupId>
        <artifactId>manik-hotdeploy-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
          <execution>
            <phase>install</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <autodeployments>
            <deployment>
              <!-- wildcard deployment -->
              <source>target/*.{war,ear,jar}</source>
              <!-- adjust the path to your installation setup -->
              <target>/opt/tomcat/webapps</target>              
            </deployment>
            </autodeployments>
            <hotdeployments>
              <deployment>
                <source>src/main/webapp</source>
                <target>/opt/tomcat/webapps/my-app.war</target>
              </deployment>                     
            </hotdeployments>
          </configuration>
        </plugin>
Coyle answered 10/9, 2022 at 7:57 Comment(0)
J
-1

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

Juliannejuliano answered 12/10, 2017 at 17:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.