【发布时间】:2017-08-16 13:30:04
【问题描述】:
是jdk编译器吗? 还是 Tomcat(或其他 Web 服务器,例如 WebLogic)? 如果Tomcat生成类文件,类文件是否通过任何编译检查,如java编译检查?
【问题讨论】:
是jdk编译器吗? 还是 Tomcat(或其他 Web 服务器,例如 WebLogic)? 如果Tomcat生成类文件,类文件是否通过任何编译检查,如java编译检查?
【问题讨论】:
Tomcat 正在调用内部 java 编译器,
compiler - Ant 应该使用哪个编译器来编译 JSP 页面。这 此的有效值与编译器属性的值相同 Ant 的 javac 任务。如果未设置该值,则默认 Eclipse 将使用 JDT Java 编译器代替 Ant。
compilerSourceVM - 源文件兼容什么JDK版本(默认值:1.6)
compilerTargetVM -> 生成的文件与哪个 JDK 版本兼容? (默认值:1.6)
另见pre compile JSP using Tomcat
Apache Tomcat 6.0 使用 Eclipse JDT Java 编译器执行 JSP java 源代码编译。
另见using WebLogic compiler in Tomcat
JSP 编译器与常规 Java 编译器非常相似,主要是 例外是他们将 JSP 文件作为“源代码”而不是 .java 文件。
【讨论】:
JSP 编译的主体是 Application Server 的责任(在这个意义上,你可以说“Tomcat”或“Weblogic”编译 JSP)。
例如Tomcat does this with the Jasper Engine,JBoss 也是这样,Weblogic also compile the JSPs automatically
... JSP Servlet 自动调用 WebLogic JSP 编译器来处理您的 JSP 页面...
基本原则是
据我所知,实际的字节码生成是如何(通过哪个工具)完成的。 Tomcat 使用 Eclipse JDT 但允许使用具有特定选项的其他编译器,weblogic 默认使用 javac and also allows an override。
另请参阅:How does jsp work?
【讨论】:
servlet容器(如tomcat)将jsp编译成java文件,然后通过JDTCompiler或AntCompiler将java文件编译成class文件,以下代码是在Tomcat中创建目标编译器的实现:
public Compiler createCompiler() throws JasperException {
if(this.jspCompiler != null) {
return this.jspCompiler;
} else {
this.jspCompiler = null;
if(this.options.getCompiler() == null) {
this.jspCompiler = this.createCompiler("org.apache.jasper.compiler.JDTCompiler");
if(this.jspCompiler == null) {
this.jspCompiler = this.createCompiler("org.apache.jasper.compiler.AntCompiler");
}
} else {
this.jspCompiler = this.createCompiler("org.apache.jasper.compiler.AntCompiler");
if(this.jspCompiler == null) {
this.jspCompiler = this.createCompiler("org.apache.jasper.compiler.JDTCompiler");
}
}
if(this.jspCompiler == null) {
throw new IllegalStateException(Localizer.getMessage("jsp.error.compiler"));
} else {
this.jspCompiler.init(this, this.jsw);
return this.jspCompiler;
}
}
}
【讨论】: