Tomcat 5.5 无法编译 Java 1.5 语法 JSP
Apache Jakarta Tomcat 5.5.x (笔者在 5.5.9 和 5.5.12 下遇到同样问题) 在安装过后,用默认配置,无法自动编译带有 Java 1.5 语法的 JSP,经过多方求证,问题是由其自带的 eclipse 编译器造成的。文档 http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jasper-howto.html 中说:
由此可见,这个编译器 common/lib/jasper-compiler-jdt.jar 是不支持 Java 5 语法的,而 Apache Ant 工程中的编译器可以替代它解决这个问题,具体方法如下:
The Java compiler from Eclipse JDT in included as the default compiler. It is an advanced Java compiler which will load all dependencies from the Tomcat class loader, which will help tremendously when compiling on large installations with tens of JARs. On fast servers, this will allow sub-second recompilation cycles for even large JSP pages. This new compiler will be updated to support the Java 5 syntax as soon as possible.
Apache Ant, which was used in previous Tomcat releases, can be used instead instead of the new compiler by simply removing the common/lib/jasper-compiler-jdt.jar file, and placing the ant.jar file from the latest Ant distribution in the common/lib folder. If you do this, you also need to use the "javac" argument to catalina.sh.
由此可见,这个编译器 common/lib/jasper-compiler-jdt.jar 是不支持 Java 5 语法的,而 Apache Ant 工程中的编译器可以替代它解决这个问题,具体方法如下:
- 将/common/lib/common/lib/jasper-compiler-jdt.jar 删除
- 将 ant-1.6.x 发布的 ant.jar 拷贝到 /common/lib/
- 修改 /conf/web.xml 文件,找到并修改如下内容,增加 compilerSourceVM 和 compilerTargetVM 两个设置:
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<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>fork</param-name>
<param-value>false</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>



3
Loading Comments...
(as a blogger member or anonymous)