2017-08-16 44 views
0

它是jdk编译器吗? 或Tomcat(或其他Web服务器,例如WebLogic)? 如果Tomcat生成类文件,那么类文件是否会通过任何编译检查来传递,比如java compling check?谁生成jsp的类文件?

回答

-1

servlet容器(如Tomcat)编译JSP到Java文件,然后通过JDTCompilerAntCompiler编译Java文件的类文件,下面的代码是实现在创建目标编译器的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; 
     } 
    } 
} 
0

的Tomcat内部调用Java编译器,

Tomcat 7 documentation

编译器 - 哪个编译蚂蚁应该用来编译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编译器执行的Java JSP源 代码编译。

参见using WebLogic compiler in Tomcat

JSP编译器很像常规的Java编译器,与主 的例外是,他们采取的JSP文件的“源代码”,而不是 .java文件。

+0

Add tomact 7 documentation – user7294900

0

JSP编译的主题是应用服务器的责任(从这个意义上说,你可以说“Tomcat”或“Weblogic”编译JSP)。

例如,Tomcat does this with the Jasper Engine,JBoss的不相同,Weblogic also compile the JSPs automatically

...的JSP Servlet的自动调用WebLogic JSP编译器来处理你的JSP页面...

的基本原理是的

  • 你可以在运行时编译JSP:(在Tomcat和JBoss,但我猜在很多服务器)有一个内部的服务器r宽,ServletFilter拦截* .jsp * .jpsx,如果需要的话,它处理请求到服务器的内部编译引擎。
  • 您可以在编译时的包装,用各种工具(Tomcat提供了一个Ant任务时,WebLogic有一个特定的模块,有时创建即使Maven插件,...)

如何(通过工具)实际的字节码生成完成,据我所知,没有指定。 Tomcat使用Eclipse JDT,但允许使用具有特定选项的其他编译器,weblogic默认使用javac and also allows an override

参见:How does jsp work?