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