简体   繁体   English

使用类型推断时,Tomcat 8.5.27编译失败,并为JSP页面显示错误“类型非法启动”

[英]Tomcat 8.5.27 compilation fails with error 'illegal start of type' for JSP pages when type inference was used

I'm using tomcat 8.5.27 and upon compiling the JSP pages with tomcat 8.5.27, I'm getting a compile error stating "illegal start of type". 我正在使用tomcat 8.5.27,并且在使用tomcat 8.5.27编译JSP页面时,出现了编译错误,指出“类型的非法开始”。

ERROR : 错误:

RESTProxy_jsp.java:30: illegal start of type
    [javac]     _jspx_imports_packages = new java.util.HashSet<>();
                                                               ^

However, if I change the tomcat to Tomcat 7.0.69, Build is observed to be SUCCESS and there is NO compile error reported. 但是,如果将tomcat更改为Tomcat 7.0.69,则发现Build成功,并且没有编译错误报告。

Upon analyzing further, I observed that Tomcat 8.x compiles the JSP pages different to that of Tomcat 7.x and it adds the below set of code to the compiled version of JSP files which causes a compilation error eventually. 经过进一步分析,我发现Tomcat 8.x编译的JSP页面与Tomcat 7.x的页面不同,并且它在JSP文件的编译版本中添加了以下代码集,最终导致编译错误。

    private static final java.util.Set<java.lang.String> _jspx_imports_packages;

     private static final java.util.Set<java.lang.String> _jspx_imports_classes;

     static {
        _jspx_imports_packages = new java.util.HashSet<>();
        _jspx_imports_packages.add("javax.servlet");
        _jspx_imports_packages.add("javax.servlet.jsp");
        _jspx_imports_packages.add("javax.servlet.http");
        _jspx_imports_classes = new java.util.HashSet<>();
        _jspx_imports_classes.add("com.abc.studio.xyz.BackEndHandler");
  }

I'm using Java 1.7.0_80, Can any of you please advise why I'm getting this error though I'm using JDK 7 and we all know that Java 7 supports type inference. 我使用的是Java 1.7.0_80,请问任何人都可以告知我为什么使用JDK 7却收到此错误,并且我们都知道Java 7支持类型推断。

tools.jar升级到Java 8后,此问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM