When I created a Servlet app in Eclipse and deployed it on a VPS, the following exception occurred.
javax.servlet.ServletException: Error instantiating servlet class [servlet.LoginServlet]
The JDK version of Eclipse and the JRE version of Tomcat did not match, causing Tomcat to be unable to execute class files. (If the Java version at compile time is higher than the Java version at runtime, an exception seems to occur.)
Error log
Root cause
java.lang.UnsupportedClassVersionError:
servlet/LoginServlet has been compiled by a more recent version of the Java Runtime (class file version 55.0),
this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [servlet.LoginServlet])
~ Abbreviated below ~
JRE version | Class file version |
---|---|
Java 8 | 52.0 |
Java 9 | 53.0 |
Java 10 | 54.0 |
Java 11 | 55.0 |
Java 12 | 56.0 |
Java 13 | 57.0 |
Java 14 | 58.0 |
Java 15 | 59.0 |
In this case, the app was compiled with version 55.0 (Java 11), but was trying to run with version 52.0 (Java 8).
Update the version on the Tomcat side or lower the version on the Eclipse side. (I decided to change the Eclipse side this time.)
The setting screen is displayed when the transition from the Eclipse window to Window> Settings` ``. When you move to the
Java> Compiler`` page, there is an item called ``
Compiler compliance level`` of the JDK, so change this to ``
1.8```.
`project name (right click)> property`
, so change it there.https://stackoverflow.com/questions/47457105/class-has-been-compiled-by-a-more-recent-version-of-the-java-environment http://www.ne.jp/asahi/hishidama/home/tech/java/version.html https://jpn.itlibra.com/article?id=21118
Recommended Posts