Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat restarts & development speed

 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification and replies. I appreciate it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic