简体   繁体   中英

Tomcat7 Starts with Incorrect Java Version

I know there are many questions on StackOverflow that provide a solution to this problem (and I have come all this way by following those solutions), but I am still stuck.The app runs fine locally on my machine, but I can't get this to work on a Ubuntu server. Here is what I have done to tackle this problem:

  1. I understand that Unsupported major.minor version 52.0 means there is a conflict with the Java version. I fixed this by installing Java 1.8 on my Ubuntu server and making it the default Java.
  2. My java -version and javac -version are 1.80_40 on Ubuntu server and 1.8.0_31 on my local machine.
  3. My $JAVA_HOME path on Ubuntu server is /usr/lib/jvm/java-8-oracle/
  4. I restarted both Tomcat and Postgres after doing this (not that it matters?)

Here are the errors I get after deploying my WAR file:

java.lang.UnsupportedClassVersionError: com/appname/servlets/getServlet: Unsupported major.minor version 52.0 (unable to load class com.appname.servlets.getServlet)
    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2948)
    org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1208)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:745)

Edit: Please don't mark it as duplicate. I feel my problem is something else because I know it is compiled and running on same versions (Java 1.8).

Even though both java -version and javac -version were showing up as 1.8 in my Ubuntu server, I noticed that for some reason Tomcat was still using 1.7 when I visited its Manager-GUI (near bottom).

This issue was fixed with the help of this question on Ask Ubuntu. Basically, JAVA_HOME needs to be updated for Tomcat as well using vi /etc/default/tomcat7 . I set mine to /usr/lib/jvm/java-8-oracle , restarted Tomcat, and now it shows the correct version in Tomcat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM