-1

I use jdk1.8.0_221 to compile (in IntelliJ). There is javac 1.8.0_191 on my server.

Any ideas why I still receive an error, like that:

Exception in thread "main" java.lang.UnsupportedClassVersionError: pp/PP 
has been compiled by a more recent version of the Java Runtime (class file 
version 55.0), this version of the Java Runtime only recognizes class file 
versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at pp.WebServer$.main(WebServer.scala:16)
at pp.WebServer.main(WebServer.scala)

P.S. Working solution has nothing to do with Java versions. See below.

P.S.1 To those, who mark question as duplicate. Other questions are on cases when Java versions are different. In my case I got an error, when versions are equal and solved it doing nothing with jdk. Absolutely different case. You should be more attentive.

JohnK
  • 264
  • 3
  • 15
  • Looks like Java 11 vs Java 8, see https://stackoverflow.com/questions/9170832/list-of-java-class-file-format-major-version-numbers --- are you sure you recompiled everything? – Robert Aug 28 '19 at 02:52
  • @Robert both Java 8 ... checked and rechecked – JohnK Aug 28 '19 at 02:55
  • 4
    Exactly how did you compile `pp/PP`? And have you ever installed Java 11? Because your error says you have. – Elliott Frisch Aug 28 '19 at 02:56
  • compiled using jdk1.8.0_221 – JohnK Aug 28 '19 at 02:58
  • 3
    The Java 8 compiler won't produce a class file with a version of 55.0. – Johannes Kuhn Aug 28 '19 at 03:33
  • @Johannes Kuhn Obviously this is not a compiler case. I experienced same error before locally and somehow I fixed it very easy. But I forgot how. Anyway, this is not a compiler case. – JohnK Aug 28 '19 at 10:09
  • I think that the IntelliJ compiler was used. How do you compile ? Have you configured the JDK 8 for the project ? – Arnaud Claudel Aug 28 '19 at 11:02
  • 1
    On a side note: It is better to rely on a build tool like Maven or Gradle to compile. Relying on your IDE is not such a good idea as it makes it harder to have reproducible builds. – Wim Deblauwe Aug 28 '19 at 11:25
  • 3
    Really, the only way you can get this error is if you try to use a class that was compiled with JDK 11, on a Java 8 runtime. You say you have "checked and rechecked" and you are convinced it is not a compiler case - but I'm afraid you are wrong. The compiler and Java runtime don't lie. – Jesper Aug 28 '19 at 11:31
  • @Arnaud Claudel Yes, IntelliJ. Project structure->Platform settings->SDK->jdk1.8.0_221 – JohnK Aug 28 '19 at 11:55
  • @Jesper In this case, shouldn't it also produce error locally? Locally it works perfectly. – JohnK Aug 28 '19 at 11:57
  • 1
    That's your sdk for development purposes, it won't do a single thing to fix how you're compiling (if using IntelliJ to build and not a build system) and it won't even affect the output code. You need to set this in a couple locations, but mostly it's setting the project bytecode target and the project language level – Rogue Aug 28 '19 at 12:05
  • @Rogue Every menu possible in Project structure is set to 8, including Project language level. – JohnK Aug 28 '19 at 12:25
  • 1
    @Roddy of the Frozen Peas, not even close. – JohnK Aug 28 '19 at 13:35

1 Answers1

-1

To fix such problem in IntelliJ do: File->Project Structure->Project Settings->Modules

In the very bottom "Dependencies storage format" select -> Eclipse(.classpath) -> Apply

Error gone.

JohnK
  • 264
  • 3
  • 15