aspose file tools*
The moose likes Tomcat and the fly likes Tomcat restarts & development speed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat restarts & development speed" Watch "Tomcat restarts & development speed" New topic
Author

Tomcat restarts & development speed

Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
I only started studying JSP/servlets about 3 or 4 months ago. One thing that bothers me a little is that when developing and testing JSP/servlets, one needs to restart Tomcat pretty often. But for development using other web technologies, such as PHP, restarting the web server is not necessary.

For all the veteran JSP/servlets developers out there, do you feel that having to restart Tomcat ofen is slowing down your web application development? Is it possible in the future that Tomcat server could detect changes in the class files and handle them automatically, without restarts?

PS: If you have some general advice for a JSP/servlets newbie, please let me know.
[ April 08, 2007: Message edited by: Wilson Gordon ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61432
    
  67

You never need to restart Tomcat -- well, almost never -- as a result of changing something. JSPs will automatically be picked up, and when a servlet is changed, you just need to restart the context. The Tomcat Manager app will help you out with that, or there are Ant tasks that I find very useful.

You can set up Tomcat to automatically reload the app when it detects a change, but I've found it to be spotty.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
Cool. I didn't know the tomcat manager exists. I just visited that page and looks useful.

Thanks!
[ April 09, 2007: Message edited by: Wilson Gordon ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The manager app has two forms; an HTML version and a command line version that works with URL Querystrings.

This means, that if you work with the command line a lot as I do, that you can
create an alias (or batch command for Windows) that reloads your app with one command.



You can also set the reloadable attribute to the <Context ../> element to true. With this attribute set to true, Tomcat will automatically reload your application if any of the classes in under /WEB-INF/classes or /WEB-INF/lib are recompiled.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
If you have some general advice for a JSP/servlets newbie, please let me know.


It is frequently worth the extra effort to put the real work in a "helper" class that can be tested outside the servlet/JSP environment.

There are just so many things that can go wrong in the combined browser - servlet container - custom code environment.

Bill
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
Thanks for the tips and info.

Do you know the equivalent batch command for Windows? For now, I just make a bookmark for the reload link so I can access it faster.

It is frequently worth the extra effort to put the real work in a "helper" class that can be tested outside the servlet/JSP environment.

There are just so many things that can go wrong in the combined browser - servlet container - custom code environment.

You mean creating some helper methods to aid in the servlet classes? I wrote a couple helper methods so far, to check if pamameter is null/empty, and also a checkRequiredFields method.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
You mean creating some helper methods to aid in the servlet classes?


No, I mean separate classes that do not depend on the servlet API and thus can be tested outside the servlet environment.

For example - the ServletRequest interface has a method getParameterMap() which returns a java.util.Map containing all request parameters names and values parsed out of the request.

Any method which takes a Map instead of a ServletRequest can be tested outside the servlet environment with a Map generated by test data.

Instead of a method generating output to a ServletRequest reference, you might write methods that output to a PrintWriter or String.

The utility of these suggestions may not be apparent now, but after your web application reaches a certain level of complexity you might want to think about them.

Bill
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Wilson Gordon:
Thanks for the tips and info.

Do you know the equivalent batch command for Windows? For now, I just make a bookmark for the reload link so I can access it faster.


I'm much of a Windows script writer and I'm not sure if anyone's ported wget to that platform. If I wanted to do something like this, I would probably just write a small Java program using java.net.URLConnection or Jakarta's commons/httpclient and wrap it with a batch script.

In a nutshell, you just need any program that can make an HTTP request to the URL that reloads your webapp. It also needs to be able to pass a username and password in that request.
Min Huang
Greenhorn

Joined: Sep 21, 2004
Posts: 16
If you attach a debugger to your webapp while its running, break somewhere, and make a code change (works in Eclipse and IDEA), that change will be reflected instantly and you won't have to reload the context.


SCJP, SCJD, SCBCD, SCWCD
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
Thanks for the clarification and replies. I appreciate it.
 
 
subject: Tomcat restarts & development speed