Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat JSP optimization at compile

Tags:

java

jsp

tomcat

I'm using Apache Tomcat 8.0.44, JSP Version 2.3

JSPs seem to get optimized when they are converted into class files

<%
    int x = 0;
    int y = 2;
%>
<p>Value is <%= y %></p>

Example in the following code when I checked the byte code, variable x is removed as it is not used, although it is available in the converted java file. This behaviour is not seen on compiling java files with javac.

Is this optimization done by Tomcat? And can this be switched on or off as required?

like image 969
Nimalan Avatar asked Feb 01 '26 08:02

Nimalan


1 Answers

Tomcat uses jasper jsp compiler which in turn uses (for tomcat 8) Eclipse JDT compiler instead of javac.

Eclipse JDT compiler performs some optimizations based on static code analysis and one of them removes unused variable. I think there is an option to preserve those if your are using jdt standalone, not sure if jasper provides such options.

like image 198
awd Avatar answered Feb 03 '26 20:02

awd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!