tomcat UnsupportedClassVersionError [英] tomcat UnsupportedClassVersionError

查看:44
本文介绍了tomcat UnsupportedClassVersionError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Mac 上有一个 bitnami Tomcat 7 安装(apache + tomcat + mysql),使用 java 1.7 76.我的 Mac 使用 java 1.8 运行时.当我将我的项目(在同一台 Mac 上的 intellij 中制作)部署到 tomcat 并尝试运行它时,我得到一个 UnsupportedClassVersionError.我用来编译项目的JDK版本无关紧要(我已经尝试过apple 1.6、oracle 1.7和oracle 1.8版本),而且我设置的语言级别似乎也无关紧要.使应用程序运行的唯一方法是使用语言级别 1.3(使用 JDK 1.7 of 1.8)

I have a bitnami Tomcat 7 installation (apache + tomcat + mysql) on my Mac, with uses java 1.7 76. My Mac uses the java 1.8 runtime. When I deploy my project (made in intellij on the same Mac) to tomcat and try to run it I get a UnsupportedClassVersionError. It does not matter which version of the JDK I use to compile the project (I've tried the apple 1.6, oracle 1.7 and oracle 1.8 versions) and it also does not seem te matter what language level I set. The only way the get the app running is using language level 1.3 (using JDK 1.7 of 1.8)

为了解决这个问题,我现在将 tomcat 设置为在 Mac 上安装的 1.8 JDK 上运行,然后我将 intellij 配置为使用相同的 JDK.现在一切正常.

To fix the problem I have now set tomcat to run on the 1.8 JDK installed on my Mac, I then configured intellij to use the same JDK. Now everything works fine.

我的问题:我是否总是需要使用与运行 tomcat 的 java 版本完全相同的 JDK 版本进行编译?还是我做错了什么.

My question: Do I always need to compile using the exact same version of the JDK as the java version that runs tomcat? Or am I doing something wrong.

完整错误:(有时还会显示 UnsupportedClassVersionError: minor version)

The complete error: (sometimes also shows UnsupportedClassVersionError: minor version)

HTTP Status 500 - javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: test/TestClass

type Exception report

message javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: test/TestClass

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: test/TestClass
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: test/TestClass
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:94)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.UnsupportedClassVersionError: test/TestClass
    org.apache.jsp.index_jsp._jspService(index_jsp.java:74)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.61 logs.

推荐答案

在编译时和运行时阶段使用一个版本的 JDK 和 JRE 始终是一个好习惯,无论是从 IDE 还是 Tomcat 使用.还要确保使用与运行测试用例相同的 JRE 版本(如果有)&tomcat 以避免遇到此类问题.

It is always a good practice to use one version of JDK and JRE for compile time and runtime phases, whether used from IDE or Tomcat. Also make sure to use same version of JRE that you used for running your test cases (if any) & tomcat to avoid running into these kind of issues.

我的问题:我是否总是需要使用完全相同的版本进行编译JDK 作为运行 tomcat 的 java 版本?

My question: Do I always need to compile using the exact same version of the JDK as the java version that runs tomcat?

如果您在较低版本上编译代码并在较高版本上运行它,有时您可能会避开这个问题,但您应该尽可能避免这种情况.因此,请尝试使用来自 IDE 的相同 JDK 版本进行编译,并使用来自 Tomcat 的相同版本的 JRE 来部署您的项目.

Sometime you might get away with this issue if you compile your code on a lower version and run it on a higher version but you should avoid this situation if possible. So try to use same JDK version from IDE for compilation and same version of JRE from Tomcat for deploying your project.

这篇关于tomcat UnsupportedClassVersionError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆