How to run javac 1.5 (or beyond) compiler for JSP compilation in Tomcat 5.5 with generics enabled (and other Java 1.5 only features like autoboxing)
By Angsuman Chakraborty, Gaea News NetworkThursday, February 3, 2005
Target Audience
Java/JSP developers on Tomcat and Application Server administrators.
Problem
Tomcat 5.5 (unlike Tomcat 5.0 and versions below) comes with Eclipse JDT compiler enabled by default for JSP compilation. JDT compiler is not jdk 1.5 compliant as of now.
Solution
To just use the javac 1.5 compiler with Java 1.4 source code compliant JSP pages (you cannot use generics or autoboxing in scripted jsp code and other Java 1.5 features) and Java 1.4 compliant target classes generated, you have to add tools.jar from your %JAVA_HOME%\lib directory to %TOMCAT_HOME%\common\lib.
Then replace the jasper-compiler-jdt.jar with ant.jar in %TOMCAT_HOME%\common\lib. Make sure you have downloaded the latest version of Ant.
To enable 1.5 features in your JSP files (like generics and autoboxing for example) you need to additionally modify %TOMCAT_HOME%\conf\web.xml file.
You need to add two init parameters as shown below in bold:
< servlet> < servlet-name>jsp< /servlet> < servlet-class>org.apache.jasper.servlet.JspServlet< /servlet> < init-param> < param-name>fork< /param-name> < param-value>false< /param-value> < /init-param> < init-param> < param-name>compilerSourceVM< /param-name> < param-value>1.5< /param-value> < /init-param> < init-param> < param-name>compilerTargetVM< /param-name> < param-value>1.5< /param-value> < /init-param> < init-param> < param-name>xpoweredBy< /param-name> < param-value>false< /param-value> < /init-param> < load-on-startup>3< /load-on-startup> < /servlet>
The compilerSourceVM and compilerTargetVM parameters indicates the compiler to assume the source is Java 1.5 compliant and the target classes generated will be Java 1.5 compliant.
Side Effect
This also enables Ant. Javac is invoked from Ant.
Please do not ask me further questions on the topic. Please read the Tomcat source code for further explanation, if required.
The procedure has been well tested and works without exception. The instructions are tailored for Windows platforms. Please adapt the instructions (minor changes) suitably for Unix/Linux platforms.
Comments are welcome.
May 29, 2009: 6:49 am
sir, |
Gobi |
January 23, 2008: 12:18 am
Hi folks. the steps i did 1) copied and pasted the tools.jar of jdk1.5 in common/lib folder Kindly help me in this regard |
Vasanth |
Suryakant |
September 12, 2006: 6:57 am
hi, |
Eric So |
August 9, 2006: 4:45 pm
Hi all, I tried to download the latest tomcat 5.5.17 and replace jasper-compiler-jdt.jar with the latest ones. It works for me. |
Gene |
April 21, 2006: 9:14 pm
I needed one more thing to do to get it to work. rename or delete jasper-compiler-jdt.jar (I just renamed it to jasper-compiler-jdt.jar.defunct) in your %catalina_home%/common/lib. |
David |
February 16, 2006: 2:21 am
The latest main comment with advice was written a year ago, but now I manage to compile JSP - including Java generic declarations - under Tomcat 5.5 when I use Tomcat with eclipse. I cannot remeber doing anything special apart from pointing tomcat server to JRE 1.5 in eclipse. Am trying to deploy to my hosting company who use JDK 1.5, but it comes up with an error on the website. Are these or any other special actions still needed? What init definitions should be looked out for, if upgraded from an older version of TOmcat. Thanks |
January 9, 2006: 10:33 pm
[...] How to run javac 1.5 (or beyond) compiler for JSP compilation in Tomcat 5.5 with generics enabled (and other Java 1.5 only features like autoboxing) -Simple Thoughts - Java and Web Technology Blog [...] |
October 31, 2005: 9:13 am
@Gana Have you made the changes as specified in the next page? I am assuming you have jdk 1.5 installed. Correct? |
gana |
October 31, 2005: 1:57 am
Hi Tried the sample. unfortunately i still get
error. have tried everything with no success. any ideas would be appreciated thanks |
June 27, 2005: 4:31 am
There are still unbalanced tags; ALL [param-name] and [param-value] are closed with [/param]. |
March 25, 2005: 4:37 am
Yaroukh and others. I figured Bachchu’s comments had an unintentional effect of garbling the comments section. I just updated them with proper escape characters so as to make WordPress happy Actually when I upgraded WordPress to 1.5, it ended up garbling the web.xml file of the post. Anyway I updated the post to enable proper display of the file. It should now be ok. let me know if you face any further problems. |
Yaroukh |
March 11, 2005: 10:41 am
I’m sorry for repeating what has already been pointed out. (The tags were interpreted and invisible therefore.) |
Yaroukh |
March 11, 2005: 10:34 am
The web.xml sample contains errors. The elements and are ending with instead of and respectively. |
February 4, 2005: 1:34 pm
Thanks for pointing it out. Actually I copied it from my web.xml file. So it was copied ok. |
Anjan Bacchu |
February 4, 2005: 12:32 pm
Hi There, Thanks for the tip. Tried it — found that the following changes to the xmls make it well-defined. <!– BEGIN new args –> |
Joshua Davies