lovespring
lovespring

Reputation: 19589

How to hot-deploy jsp file to tomcat?

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 ?

Upvotes: 3

Views: 13779

Answers (2)

subject42
subject42

Reputation: 51

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 :)

Upvotes: 1

parsifal
parsifal

Reputation: 501

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.

Upvotes: 7

Related Questions