3

I don't want to build a war file each time I make a little edit in a JSP file. I want things to work like with PHP. How can I hot-deploy to a tomcat server? Is hot-deploy a java standard?

Can this kind of hot-deploy be used in a released version of my software ?

kc2001
  • 5,008
  • 4
  • 51
  • 92
lovespring
  • 19,051
  • 42
  • 103
  • 153
  • http://stackoverflow.com/questions/7885551/tomcat-hot-deploy – matt snider Feb 21 '13 at 21:39
  • FYI JSR-88 describes the Java EE deployment standard: http://download.oracle.com/otn-pub/jcp/j2ee_deployment-1.2-mrel-eval-oth-JSpec/j2ee_deployment-1_2-mrel-spec.pdf. From my experience frequent hot-deployment often cause the class not released from memory and causing OOME PermGen exception. – gerrytan Feb 21 '13 at 21:42
  • Use an exploded war and copy the JSP file over. – Dave Newton Feb 21 '13 at 21:46
  • JRebel is a good tool for hot deployment. It also supports reinitialization of your beans if you use a DI framework. But if it's just a JSP file then all you need to do is to copy the file over – rootkit Feb 21 '13 at 21:52

2 Answers2

7

As the linked question doesn't really go into details ...

In $CATALINA_BASE/conf/server.xml, you need to configure the local server to unpack WARs. Here's the example from my development server:

 <Host appBase="webapps" autoDeploy="true" deployOnStartup="true" 
       deployXML="true" name="localhost" unpackWARs="true">

By default, Tomcat will check for changes to JSP files. In fact, you have to change that for production, as described here.

With these changes in place, you will find your web-app in $CATALINA_BASE/work/Catalina/localhost (assuming, again, a default install; if you're configuring server name, it won't be localhost). Edit the file in-place, and the changes will appear when you load the page next.

Is this kind of hot-deploy can be used in a release versioin of my software

Not if you want to avoid hard-to-track-down bugs.

parsifal
  • 501
  • 2
  • 4
1

I faced the same problem today and using an exploded .war just didn't cut it for me.

My solution was to also use the following context.xml file in Tomcat ($CATALINA_BASE\conf\context.xml):

<Context reloadable="true"> 
    <Resources cachingAllowed="false" cacheMaxSize="0" />

    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <Manager pathname="" />
</Context>

I also used the following in my Jsp's for the client side cache:

<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0);
%>

after tomcat restart it was possible to just copy the Jsp's to $CATALINA_BASE\webapps\<context>\WEB-INF\...

and do a quick reload (F5) in my browser to see the changes.

Bonus: Tomcat also does a reload on all its ressources when i copy .class or .jar files into /WEB-INF now :)

subject42
  • 51
  • 5
  • by does a reload you mean it redeploy/restarts the webapp? Anyway, it appears that WatchedResource only *adds* additional things it watches, and that if you have `reloadable=true` it automatically also watches web.xml and WEB-INF/lib/* as well: https://stackoverflow.com/a/1800802/32453 – rogerdpack Oct 12 '17 at 18:06