无法使用 Java 1.8 在 JBoss 5.1 中编译 JSP 文件

Not able to compile JSP files in JBoss 5.1 with Java 1.8

无法在 JBoss 5.1 和 Java 1.8 中编译 JSP 文件。 能够编译常规 Java 文件,甚至可以完成没有 JSP 的 Spring 项目。

如果我们为那些 JSP 个文件保留已编译的 class 个文件,它工作正常。

以下是我尝试 运行 一个 JSP 文件时遇到的错误:

2016-07-15 14:56:00,758 ERROR [org.apache.jasper.compiler.Compiler] (http-0.0.0.0-80-31) Compilation error
org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
        at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:369)
        at org.apache.jasper.compiler.JDTCompiler.findType(JDTCompiler.java:206)
        at org.apache.jasper.compiler.JDTCompiler.findType(JDTCompiler.java:163)
        at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:97)
        at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)
        at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:101)
        at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:169)
        at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2241)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:974)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1184)
        at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:535)
        at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:743)
        at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
        at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:429)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:313)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:300)
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
        at org.apache.catalina.valves.RequestDumperValve.invoke(RequestDumperValve.java:151)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:745)
2016-07-15 14:56:01,873 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/].[jsp]] (http-0.0.0.0-80-31) Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 1 in the generated java file
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

Stacktrace:
        at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
        at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
        at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:313)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:300)
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
        at org.apache.catalina.valves.RequestDumperValve.invoke(RequestDumperValve.java:151)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:745)

尝试设置 JAVA_HOME 指向 JDK 的环境变量。 JBoss 应该能够将 tools.jar 提取到 classpath 中并使用它代替 JDT编译

您必须从 JBoss 5.1 中删除 jasper-jdt.jar。您会在以下内容中找到:

jboss-5.1.0.GA\server\default\deploy\jbossweb.sar\jasper-jdt.jar

我在使用带有 JBoss 5.1 AS 和 jdk 1.8 的 jasperreport 库时遇到了类似的问题(jdk 1.7 没问题)。

我决定从 JBoss 5.1 中删除 jasper-jdt.jar。 在我的项目 pom 中,我将依赖项更新为 Java (ECJ) 的 Eclipse 编译器,但在我删除 jasper-jdt.jar 之前,问题仍然存在:

<dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>6.3.0</version>
        <exclusions>
            <exclusion>
                <groupId>eclipse</groupId>
                <artifactId>jdtcore</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jdt.core.compiler</groupId>
        <artifactId>ecj</artifactId>
        <version>4.5.1</version>
    </dependency>

在我的例子中,我遇到了 jboss-5.1.0.GA 的麻烦,因为我使用 jsp(旧版本)制作了一个旧应用程序。我知道 jbossweb 是编译 jsp 的地方。因此,我将 jasper-jdt.jar 的结构与 ecj-4.3.1.jar 的结构进行了比较,发现两者非常相似。然后,我应用 ecj-4.3.1.jar 代替(替换)jasper-jdt.jar,将 ecj-4.3.1.jar 重命名为 jasper-jdt.jar。 运行 后更换成功。