0

I have written a webapp in Eclipse, deployed in Tomcat 8. The webapp includes an email utility, by which users can submit contact info that gets emailed to me from the webserver.

It works when I run the webapp from within Eclipse (using a Tomcat instance on my local host).

I have deployed the webapp to the server, and it appears to work fine, until I try to send the contac info.

When I click the Submit button in the form that calls the servlet, I get this exception:

 java.lang.UnsupportedClassVersionError: com/electraink/rental/servlets/ContactInfo has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class com.electraink.rental.servlets.ContactInfo)
org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2500)
org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:860)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1302)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:844)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)

I don't know where the mismatch is. The server on which the Tomcat8 instance runs shows this version of Java:

[root@web1 downloads]# java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

The Eclipse project uses jdk-1.8.0_45.

It looks to me like Tomcat is using a newer, not older, JVM than the one in which the webapp was built.

Where's the mismatch? Which Java do I need to update, and to what? (I originally used Java 9 when building the webapp in Eclipse until I saw this error, then I downgraded to Java 8).

Thanks, Jerry

Ryuzaki L
  • 37,302
  • 12
  • 68
  • 98
Jerry
  • 11
  • 1
  • Just set the same java that eclipse ide is configured to use to the apache tomcat. – NiVeR Jul 21 '18 at 23:21
  • As you can see from the [duplicate answer](https://stackoverflow.com/q/10382929/5221149), class `com.electraink.rental.servlets.ContactInfo` was compiled using Java 9 *(class file version 53.0)*, while Tomcat is running Java 8 *(class file versions up to 52.0)*. – Andreas Jul 21 '18 at 23:23
  • *"I originally used Java 9 when building the webapp in Eclipse until I saw this error, then I downgraded to Java 8"* Then you need to do a full re-build. In Eclipse, select pull-down menu `Project` > `Clean...` – Andreas Jul 21 '18 at 23:25
  • I have rebuilt the Eclipse project multiple times with the build path specifying Java 8, yet the exception still cites class file version 53. Also, this is a webapp. The exception doesn't get thrown until the servlet is called, and the servlet shouldn't be compiled in Eclipse anyway, it gets compiled at runtime. That much should be guaranteed, since I erase the entire app directory under Tomcat8/webapps each time I deploy the app, at which time I retart tomcat. So where is Java 9 getting invoked? What do I need to change to get all processes on the same jre? – Jerry Jul 22 '18 at 00:02

0 Answers0