tomcat-embed启动失败一例

tomcat-embed启动失败一例-刘师傅
刘师傅
擅长邻域:Java,HTML,JavaScript,CSS,SQL,ORACLE,MySQL,SQL SERVER,Spring 全家桶

2020-11-04 15:02:12   210浏览 分类: Java

某为客户系统原先使用环境为tomcat 7+jdk1.7,现由于项目架构调整,改为使用tomcat-embed8和jdk1.8,直接替换jar包后,项目启动失败。

起初怀疑是javax包冲突,尝试过替换和删除javax.servlet、javax-jsp等jar包,故障依旧,此路不通。
后来又怀疑是tomcat-embed8依赖组件不全,翻看mvnrepository上的依赖项,发现所有必要依赖都已经引入。
将日志输出等级调至最低,发现有大量JSP文件编译失败的日志信息,遂检查JSP编译相关设置和Jar包,经排查发现该项目附带的ecj组件版本较低,在低版本tomcat-embed上运行编译没有问题,但在高版本tomcat就有问题,升级该jar包后,问题解决。
至于tomcat为什么用ecj编译jsp而不是标准javac,这又是另外一个问题,爆栈上有这样一段话,可以揣摩一下:

Eclipse has implemented its own compiler called as Eclipse Compiler for Java (ECJ).

It is different from the javac, the compiler that is shipped with Sun JDK. One notable difference is that the Eclipse compiler lets you run code that didn't actually properly compile. If the block of code with the error is never ran, your program will run fine. Otherwise, it will throw an exception indicating that you tried to run code that doesn't compile.

Another difference is that the Eclipse compiler allows for incremental builds from within the Eclipse IDE, that is, all code is compiled as soon as you finish typing.

The fact that Eclipse comes with its own compiler is also apparent because you can write, compile, and run Java code in Eclipse without even installing the Java SDK.

A few examples where ECJ is preferred over javac is:

Apache Tomcat uses ECJ to compile JSPs,
IntelliJ IDEA has support for ECJ, as of GNU Compiler for Java (GCJ) 4.3,
GCJ integrates with ECJ,
Liferay builds with ECJ.

引用文章原文地址: https://stackoverflow.com/questions/3061654/what-is-the-difference-between-javac-and-the-eclipse-compiler

好文章就要一起分享哦!分享海报

此处可发布评论

评论(0

暂无评论,快来写一下吧
客服QQ 1913284695