I have a project built with Java 7 (project pom excerpt) :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

It has a dependency with a module built with Java 8 (dependency pom excerpt) :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

I've deployed and run my application on a server running with Java 7, and I get this error :

java.lang.UnsupportedClassVersionError: com/h/i/c/u/e/TradeStatus : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getDeclaredMethods(Class.java:1808)
at ...

How can I fix this, knowing that I can't change the JRE on the server, and that I can't change the fact that the module is built with Java 8 ?

2 Answers

1
Sambit On

UnsupportedClassVersionError ... Major Minor occurs when you have a library built in higher version of java and you want to use in your application which is running in lower version. So there are two possible solutions.

  • First build the library with code changes in required version of JDK
  • Upgrade your JDK version so that both library and your application will work.
0
Lesiak On

It really depends to what extent the library uses Java8 JVM features. You can try using a retrorlanslator like Retrolambda on the library. https://github.com/luontola/retrolambda

Check discussions in Can Java 8 code be compiled to run on Java 7 JVM?

New server or JVM upgrade on the existing one is much better use of your time through.