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)
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.
Pages: 1 2
Filed under How To, Java Software, Open Source Software, Web |
|
RSS 2.0 |
Trackback this Article
|
Email this Article
You may also like to read |




































February 4th, 2005 at 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 –>
<init-param>
<param-name>compilerSourceVM</param>
<param-value>1.5</param>
</init>
<init-param>
<param-name>compilerTargetVM</param>
<param-value>1.5</param>
</init>
<!– END new args –>
February 4th, 2005 at 1:34 pm
Thanks for pointing it out. Actually I copied it from my web.xml file. So it was copied ok.
Somehow while publishing wp seems to have garbled it.
March 11th, 2005 at 10:34 am
The web.xml sample contains errors. The elements and are ending with instead of and respectively.
March 11th, 2005 at 10:41 am
I’m sorry for repeating what has already been pointed out. (The tags were interpreted and invisible therefore.)
March 25th, 2005 at 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.
June 27th, 2005 at 4:31 am
There are still unbalanced tags; ALL [param-name] and [param-value] are closed with [/param].
June 28th, 2005 at 8:04 am
Thanks Yaroukh. Fixed.
October 31st, 2005 at 1:57 am
Hi Tried the sample. unfortunately i still get
generics are not supported in -source 1.4
(try -source 1.5 to enable generics)
error. have tried everything with no success. any ideas would be appreciated
thanks
October 31st, 2005 at 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?
January 4th, 2006 at 7:51 am
Thanks man
Thank you very much
January 9th, 2006 at 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 [...]
February 16th, 2006 at 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
David
April 21st, 2006 at 9:14 pm
I needed one more thing to do to get it to work.
as challanger9 states here
rename or delete jasper-compiler-jdt.jar (I just renamed it to jasper-compiler-jdt.jar.defunct) in your %catalina_home%/common/lib.
Then grab the latest ant (ant.jar is all u really need).
Then add the two parameters above, restart tomcat and BAM….works.
April 28th, 2006 at 12:23 pm
Thanks for sharing.
August 9th, 2006 at 4:45 pm
Hi all,
I tried to download the latest tomcat 5.5.17 and replace
jasper-compiler-jdt.jar
jasper-compiler.jar
jasper-runtime.jar
with the latest ones. It works for me.
September 12th, 2006 at 6:57 am
hi,
I hav installed jdk1.5 at d drive.Now i m trying to run programs for RMI but when i set the path
and trying to compile the program i got an error
i.e.javac is not internal or external command.
Plz tell me how to set the path correctly
i did this:
d:\rmi>set path=d:\jdk1.5\bin
d:\rmi>set classpath=%classpath%;.;
September 13th, 2006 at 3:46 am
Thanks,
You saved my day.
January 23rd, 2008 at 12:18 am
Hi folks.
I tried all the steps mentioned in this page.
Still am getting the error cannot compile the generics features in the jsp page.
the steps i did
1) copied and pasted the tools.jar of jdk1.5 in common/lib folder
2) then replaced the jasper-compiler-jdt.jar file with lates ant.jar(1.7)
3) and finally i made the web.xml corrections for the compilerSourceVM tag
Kindly help me in this regard