This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JSP and the fly likes How to precompile all JSPs at once in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic

How to precompile all JSPs at once in Tomcat

Aaron Beverly

Joined: Sep 10, 2003
Posts: 19
Does anyone know if there is a way to make Tomcat (v. 4.1.24) compile all of the JSPs in a given context at one time, say, for instance, at server startup or perhaps upon some explicit command?
It would be nice if when I make changes and deploy them to a live webapp, I could just go ahead and tell tomcat to precompile everything it finds in the webapp context, prior to any particualr request for a JSP.
Thanks in advance for any help!
Aaron L. Beverly
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
You don't need any Tomcat specific functionality to get all of your servlets/jsp pages translated and compiled before a request is ever made. You should use the deployment descriptor (web.xml file) of your web application. Simply use the tag <load-on-startup>1</load-on-startup> under the <servlet> element. For a jsp page, it looks like this:
You should put the load-on-startup element in every servlet element where the body content of the tag is the order that the servlet should be translated/compiled.

Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Check this link
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63348

Hmmm, seems that the web.xml route would be completely unweildly for anything but a rather trivial web application. Most of mine tend to have in the hundreds of JSP pages.
I had started writing a 'web monkey' servlet to try to hunt down and hit every JSP, but I never really finished it. Also, most of the JSPs expect a controller to forward to them, so a direct hit may cause them to compile, but tends to generate a bunch of errors that I'd rather not have clogging the log files.
The Ant script is a great idea, but there's still the errors-in-the-log problem. Anybody got a wifty idea for that one?
[ September 26, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Aaron Beverly

Joined: Sep 10, 2003
Posts: 19
Thanks for the suggestions. Yeah, the load-on-startup solution is really not practical in my case, since I have about 1,000 JSPs in this web-app. Thanks, tho for the link to the script that precompiles JSPs. I will check it out. Hopefully it can do the trick.
Pramod Tiwari

Joined: Dec 13, 2011
Posts: 6
Nice blog.
but i m using tomcat 8 and want to pre-compiled all jsp files at the time war file build.]

I created war file and upload to tomcat/webapps folder but when open any page at that time jsp file will compile (created *.java and *.class file).
But i want to do When War file Compile at tomcat startup at that time want to compile all jsp files.

If anybody have solution please tell me. i tried lots of method but still did not find any way.

Thanking you !!!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17148

Please don't ask the same question in more than one forum. It causes people to get confused.

I'm locking this thread. Answers should be posted to this one:

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: How to precompile all JSPs at once in Tomcat
It's not a secret anymore!