简体   繁体   中英

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".

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.

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.

    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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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