0

I am downgrading a small application from Tomcat 8/JRE 1.8 to Tomcat 7/JRE 1.7 for infrastructure reasons. Nevertheless, when I set up JRE to 1.7 and compiler compliance level to 1.7, I got this error in Tomcat 7 start-up. I've tried everything in this question, without success.

  • Compiler compliance level: 1.7
  • Targeted runtimes: Apache Tomcat v7.0
  • JRE System Library: jdk1.7.0_80

Maven POM snippet:

  <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

Any help would be worthy. Thanks.

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/compoT7]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1119)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
    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: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/compoT7]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    ... 6 more
Caused by: java.lang.UnsupportedClassVersionError: org/springframework/web/SpringServletContainerInitializer : Unsupported major.minor version 52.0 (unable to load class org.springframework.web.SpringServletContainerInitializer)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:3209)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:1373)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1861)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:278)
    at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:197)
    at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:158)
    at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1579)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1280)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:888)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:388)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5522)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    ... 6 more
Alex
  • 3,325
  • 11
  • 52
  • 80
  • Everywhere I look, the answers turns around changing JRE and Compiler Compliance level. Nevertheless, it seems to be something different and trickier. – Alex Mar 22 '18 at 20:51
  • 1
    Which Spring Boot/ Spring Version do you use? – khmarbaise Mar 22 '18 at 21:15
  • spring (webmvc, jdbc,orm,data-jpa) 5.0.2.RELEASE – Alex Mar 22 '18 at 21:20
  • 2
    So Spring 5.X is JDK 8 requirement which is your problem. See https://projects.spring.io/spring-framework/ If you like to run with JDK 7 you have to downgrade to Spring 4.X.... – khmarbaise Mar 22 '18 at 21:44

3 Answers3

2

Caused by: java.lang.UnsupportedClassVersionError: org/springframework/web/SpringServletContainerInitializer : Unsupported major.minor version 52.0 (unable to load class org.springframework.web.SpringServletContainerInitializer)

It appears that the version of Spring you are using was compiled on Java 8. Look at your Spring version and check the JRE level. You may have to downgrade Spring.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
Steve11235
  • 2,849
  • 1
  • 17
  • 18
1

It is simple:

org.springframework.web.SpringServletContainerInitializer class from Spring dependency was compiled with 1.8 JDK. Only one thing you can do is downgrade Spring dependencies to version compiled with 1.7 JDK.

If you have them defined in one of your pom.xml just downgrade their version.

If it is a transitive dependency downgrade main depenendency which uses lesser Spring version

or exclude 1.8 compiled dependencies and add lesser version explicitly.

Vadim
  • 4,027
  • 2
  • 10
  • 26
0

You can use the Enforcer plugin to identify which libraries are compiled with the wrong version. It will tell you exactly which jar(s) and what version they are compiled for.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>specifyLatestVersionHere</version>
  <executions>
    <execution>
      <id>jdk-check</id>
      <phase>validate</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <enforceBytecodeVersion>
            <maxJdkVersion>1.7</maxJdkVersion>
          </enforceBytecodeVersion>
        </rules>
        <fail>true</fail>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>extra-enforcer-rules</artifactId>
      <version>1.0-beta-6</version>
    </dependency>
  </dependencies>
</plugin>
user944849
  • 14,524
  • 2
  • 61
  • 83