Thursday, November 17, 2005

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 中说:
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>

11 comments:

leep said...

非常感谢,看了你的文章后受益良多。

fbysss said...

少了一步操作:还需要把tools.jar拷贝到tomcat/common/lib中

Gregory said...

我想这不是必须的,至少我没有这么做,但是一切能够正常的运行。如果正确的配置了 JDK,tools.jar 所在的目录,通常应该是 Class Path 的一部分。

Coach Factory said...

ferragamo shoes, supra shoes, abercrombie and fitch, ray ban pas cher, wedding dresses, nfl jerseys, reebok outlet, hermes, juicy couture outlet, air max, lululemon, p90x, ghd, timberland, mulberry, lancel, hogan, new balance shoes, birkin bag, mont blanc, asics, nike air max, ugg boots, soccer jerseys, hollister, rolex watches, north face outlet, beats by dre, montre pas cher, nike free, louis vuitton, ugg boots, herve leger, chi flat iron, vans, ralph lauren, oakley pas cher, jimmy choo, insanity, converse shoes, louis vuitton, karen millen, celine handbags, bottega veneta, marc jacobs, soccer shoes, mcm handbags, yoga pants, burberry, valentino shoes

Coach Factory said...

oakley outlet, moncler outlet, oakley vault, rayban, ray-ban, canada goose outlet, oakley vault, oakley sunglasses cheap, cheap sunglasses, cheap oakley, ugg boots, ugg, ray ban, ralph lauren, oakley vault, ray ban outlet, raybans, ray ban, cheap sunglasses, ray ban sunglasses outlet, louboutin, oakley, cheap sunglasses, canada goose, canada goose, canada goose, cheap oakley sunglasses, cheap oakley sunglasses, ray bans, oakley sunglasses outlet, oakley sunglasses cheap, oakley sunglasses outlet, discount oakley sunglasses, ray ban, ray bans, rayban, cheap oakley sunglasses, tn pas cher, ray ban outlet, oakley outlet, oakley outlet, moncler, oakley sunglasses outlet, canada goose, gucci, moncler, moncler, canada goose outlet, oakley sunglasses cheap

Coach Factory said...

coach factory, oakley sunglasses, polo ralph lauren outlet, kate spade outlet, michael kors, ray ban sunglasses, michael kors outlet, louboutin, ray ban, longchamp, louis vuitton handbags, air jordan, louboutin, prada handbags, gucci outlet, oakley sunglasses, prada outlet, coach outlet store, nike shoes, louis vuitton, polo ralph lauren, air max, michael kors outlet, louboutin, michael kors outlet, toms shoes, tory burch outlet, burberry outlet online, tiffany and co, air max, jordan shoes, nike air max, coach outlet, true religion jeans, oakley sunglasses, ray ban sunglasses, burberry outlet online, nike free, michael kors, true religion outlet, louis vuitton outlet online, true religion, chanel handbags, polo ralph lauren outlet, coach purses, nike air max, nike free, ralph lauren, longchamp outlet

oakleyses said...

oakley sunglasses, longchamp outlet, ugg boots, chanel handbags, nike air max, longchamp, christian louboutin outlet, michael kors outlet, oakley sunglasses, tiffany and co, replica watches, tory burch outlet, nike air max, ray ban sunglasses, michael kors outlet, louboutin shoes, jordan shoes, louis vuitton outlet, louis vuitton, ray ban sunglasses, longchamp outlet, polo ralph lauren outlet, replica watches, kate spade outlet, oakley sunglasses, polo ralph lauren outlet, cheap oakley sunglasses, ugg boots, nike free, tiffany jewelry, michael kors outlet, uggs on sale, louis vuitton outlet, michael kors, oakley sunglasses, louboutin, louis vuitton, michael kors outlet, ray ban sunglasses, prada handbags, louis vuitton, burberry, burberry outlet online, gucci outlet

oakleyses said...

nike blazer, michael kors, nike free run uk, nike air max, true religion jeans, true religion jeans, air jordan pas cher, nike air max, ralph lauren uk, timberland, air max, nike roshe, tn pas cher, louboutin pas cher, true religion outlet, vans pas cher, coach outlet, hermes, ralph lauren pas cher, nike free, coach purses, michael kors, oakley pas cher, mulberry, hollister pas cher, lacoste pas cher, new balance pas cher, ray ban pas cher, vanessa bruno, burberry, hollister, michael kors, kate spade handbags, coach outlet, abercrombie and fitch, lululemon, coach factory outlet, nike roshe run, north face, nike air max, ray ban uk, michael kors, true religion jeans, converse pas cher, north face, air force, hogan, sac longchamp, longchamp pas cher, sac guess

oakleyses said...

ferragamo shoes, iphone 6s plus cases, babyliss, longchamp, reebok shoes, nike trainers, asics running shoes, oakley, iphone 5s cases, celine handbags, hollister, nfl jerseys, jimmy choo shoes, birkin bag, iphone 6s cases, iphone cases, mcm handbags, bottega veneta, giuseppe zanotti, iphone 6 plus cases, abercrombie and fitch, p90x workout, beats by dre, herve leger, north face outlet, instyler, louboutin, soccer jerseys, lululemon, nike roshe, s5 cases, timberland boots, mac cosmetics, soccer shoes, valentino shoes, insanity workout, vans shoes, hollister, ralph lauren, wedding dresses, ipad cases, chi flat iron, north face outlet, iphone 6 cases, nike air max, ghd, mont blanc, baseball bats, new balance, nike huarache

oakleyses said...

ugg pas cher, vans, moncler, moncler, canada goose, louis vuitton, ugg boots uk, canada goose, toms shoes, doudoune canada goose, moncler, louis vuitton, louis vuitton, ugg australia, juicy couture outlet, moncler, supra shoes, doke gabbana outlet, gucci, karen millen, moncler outlet, hollister, moncler, hollister, canada goose, louis vuitton, ray ban, marc jacobs, pandora jewelry, michael kors outlet online, moncler, swarovski crystal, pandora jewelry, wedding dresses, thomas sabo, moncler, bottes ugg, sac louis vuitton pas cher, nike air max, barbour, barbour jackets, pandora charms, canada goose outlet, canada goose uk, michael kors outlet, converse outlet, links of london, canada goose outlet, pandora charms, canada goose

mmjiaxin said...

black friday deals
discount oakley sunglasses
oakley sunglasses wholesale
designer handbags,handbags outlet,cheap handbags,purses and handbags,wholesale handbags,designer bags,bags outlet,handbags wholesale,cheap purses,discount handbags,handbags sale,wholesale purses,handbags and purses,designer purses
mont blanc pens
swarovski outlet
camisetas futbol baratas
mulberry uk
valentino outlet
michael kors online outlet
fitflops sale
cheap wedding dresses
mlb jerseys
giuseppe zanotti outlet
converse shoes
soccer jerseys wholesale
tiffany and co
ferragamo outlet
true religion jeans
oakley sunglasses wholesale
mm1205