Unable to load class com.haulmont.restapi.sys.CubaRestApiServlet

Hello,
I’m using java version “1.8.0_121”, Apache Tomcat 8.5, and cuba studio v6.4.3.
If I run the application using the (Re)start application all works fine, the application deploys and runs successfully, but when I build the WAR files for distribution and deploy them to the production server (Using also Tomcat 8.5 with java 1.8.0_121) I get several severe exceptions.

I am using the following task to build the WAR files as suggested in the documentation:

groovy
task buildWar(type: CubaWarBuilding) {
    singleWar = false
    appHome = '.'
    appProperties = ['cuba.automaticDatabaseUpdate' : true]
    includeJdbcDriver = true
}

And this is the stacktrace that is printed when the app.war is being deployed:


14-Apr-2017 21:13:07.722 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
14-Apr-2017 21:13:07.824 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/app-core] startup failed due to previous errors
14-Apr-2017 21:13:07.840 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\app-core.war has finished in 8,667 ms
14-Apr-2017 21:13:07.844 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\app.war
14-Apr-2017 21:13:17.386 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/app]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.UnsupportedClassVersionError: com/haulmont/restapi/sys/CubaRestApiServlet : Unsupported major.minor version 52.0 (unable to load class com.haulmont.restapi.sys.CubaRestApiServlet)
	at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2271)
	at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1254)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
	at org.atmosphere.util.IOUtils.isAtmosphere(IOUtils.java:348)
	at org.atmosphere.cpr.AtmosphereInitializer.onStartup(AtmosphereInitializer.java:66)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 10 more

Any idea how can I troubleshoot and fix this error?

Thank you in advance!

Hi,

the error Unsupported major.minor version 52.0 is a java version mismatch. 52 - Java 8 is required, but the runtime it executes (your server) does not have java 8 installed. Upgrade to JRE 8 should fix the problem.

More information @see: java - Unsupported major.minor version 52.0 - Stack Overflow

EDIT: sorry just read about the java versions in the first sentence. Can you do a “java --version” on the machine?

Bye
Mario

Yes you’re right, I’ve noticed after that I posted this question that when I upgraded to JDK8 the tomcat configuration was still pointing to JDK7.
Thank you and sorry for bothering you.

Unsupported major.minor version error is because of Java version mismatch. It happens when you compile your projects on higher version of java(e.g. jdk 1.8) and then run it on a lower version (e.g. jdk 1.7). Depending on your situation, you have two ways to resolve this error: compile your code for an earlier version of Java, or run your code on a newer Java version. Sometimes you may have more than one version of Java SDK installed in your machine. Make sure the application you are running is pointing to the right or highest version available . It is better you need to install both JRE/JDK with the same version.