2

Since JSPs adhere to a standard API, can I precompile them in my projects and then deploy the result on any server?

Specifically, I'm using Tomcat, JBoss and WebSphere.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820

2 Answers2

4

No, not really. If you look at the java source that gets created by the JSP compiler, you'll see that it extends a base class that's proprietary to the container. For example, JBoss 4's servlet container generates JSP classes that extend org.apache.jasper.runtime.HttpJspBase, which is Tomcat and JBossWeb-specific.

So you might be able to reuse pre-compiled JSPs between different tomcat-based servers, but even then it might not work.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • +1. Another point is that the compiler itself tends to be a different class altogether - Tomcat uses the Jasper compiler, which need not be the case with other servlet/JSP containers. NB: WebLogic uses the weblogic.appc class to flag off the compilation process. – Vineet Reynolds Jul 27 '10 at 10:04
1

Since the servlet/JSP engines are different between app servers there could be byte code added that's not portable.

I'd have to write a test to confirm it. If I have time I'll try it with Tomcat and WebLogic and report back.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • You will be if it expects app server specific JARs to be in the CLASSPATH and doesn't find them. – duffymo Jul 27 '10 at 12:08