1

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

kaoscify
  • 1,743
  • 7
  • 37
  • 74
  • how are you exactly running your app? do you have older java versions installed on your server? are you sure those apps aren't using older Java versions (maybe someone hardcoded them into some startup scripts?) – Mateusz Dymczyk Apr 07 '15 at 04:39
  • @MateuszDymczyk – When I right-click projectName > Properties in NetBeans, I see Java Platform is JDK 1.8 in Libraries tab. In Sources tab, I see Source/Binary Format as JDK 8. – kaoscify Apr 07 '15 at 04:45
  • This is happening because of target version of java at compilation time is higher than what you are trying to run now. (e.g: compiled targeted version Java 1.8 and running in Java 1.7) Refer to this question. http://stackoverflow.com/questions/22489398/unsupported-major-minor-version-52-0 – Jude Niroshan Apr 07 '15 at 04:45
  • @JudeNiroshan – It’s compiled in Java 1.8 and running on 1.8 as well. – kaoscify Apr 07 '15 at 04:47
  • 2
    Close voters: I reopened this question because it appears to have some odd nuance that isn't covered by the standard answers. – chrylis -cautiouslyoptimistic- Apr 07 '15 at 05:40
  • @chrylis – Apache Tomcat/7.0.52 (Ubuntu). I just noticed that when I log on to the Manager-GUI, I see JVM version as 1.7. Why? Using terminal, I see 1.8. I even restarted Tomcat. – kaoscify Apr 07 '15 at 05:41
  • 1
    Does your Tomcat installation come with its own JRE? – chrylis -cautiouslyoptimistic- Apr 07 '15 at 05:42
  • @chrylis – This is my first time doing this so I used these instructions to install Tomcat 7: https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-7-on-ubuntu-14-04-via-apt-get. It seems like `sudo apt-get install default-jdk` may have installed 1.7 on Tomcat? – kaoscify Apr 07 '15 at 05:45
  • 2
    @chrylis – I solved it. If you hadn’t asked that question, I wouldn’t have known. I updated `JAVA_HOME` in `/etc/default/tomcat7`: http://askubuntu.com/questions/154953/specify-jdk-for-tomcat7. Now I see 1.8 in Manager-GUI. – kaoscify Apr 07 '15 at 05:53
  • 1
    Maybe you should change the title into something like "Tomcat starts with obsolete java version", so people running into the same problem can find your answer. – Bram Apr 07 '15 at 07:54
  • And post your solution as an answer. – chrylis -cautiouslyoptimistic- Apr 07 '15 at 13:45

2 Answers2

0

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.

Community
  • 1
  • 1
kaoscify
  • 1,743
  • 7
  • 37
  • 74
0

For fixing the Java version problem in windows environment we need to change the path of jvm.dll to the expected Java home dir path by running the Tomcat7w.exe as administrator.

e.g - C:\Program Files\Java\jdk1.8.0_221\jre\bin\server\jvm.dll

If you are unable to open the configuration window by running Tomcat7w.exe then a ugly hack can be done to the registry entry for the registered Tomcat7 service to change the JVM path as below -

enter image description here

The Tomcat service needs to be refreshed (in services.msc) and restarted for the Java changes to take effect. Hope this answer saves someones time who are facing similar issue in windows environment.

Mohsin
  • 852
  • 8
  • 28