0

this "unsupported major.minor 52.0 version" error is driving me nuts.

How can I get scala to use jdk 1.7. My SBT project needs to be 1.7 and I cannot run sbt or scala unless I set my java_home to 1.8.

My google foo is not strong since there are so many results for this vague-keyword problem.

Do I need to install different version of scala? sbt?

Thanks,

Edit More details:

 $ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home

$ sbt -sbt-version 0.13.16 ~jetty:start
[info] Loading project definition from /Users/dan/Projects/temp/ssltester/project
[info] Set current project to ssltester (in build file:/Users/dan/Projects/temp/ssltester/)
[info] starting server ...
[success] Total time: 0 s, completed Nov 7, 2017 4:35:49 PM
1. Waiting for source changes... (press enter to interrupt)
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/jetty/runner/Runner : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    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:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

[info] waiting for server to shut down...

build.sbt

name := "ssltester"

version := "1.0"

scalaVersion := "2.11.11"

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.2"

libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided"

libraryDependencies += "org.codehaus.groovy.modules.http-builder" % "http-builder" % "0.5.2"

enablePlugins(JettyPlugin)

./project/build.sbt

addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "3.0.1")
dlite922
  • 1,924
  • 3
  • 24
  • 60
  • 1
    *"Do I need to install different version of scala?"* You need to run a version of scala that is compatible with Java 7. Since you don't say which version of scala you *are* running, how can we answer that question? – Andreas Nov 07 '17 at 21:17
  • I figured there was, I tried finding a matrix (scala to jdk versions) online. Shouldn't that be the first result on google? I want to run any version of scala on jdk 1.7. It doesn't matter at this point but I'm testing a simple script on a server that runs 1.7. I need to write a simple JVM app to run on jdk1.7 and it's been a pain. – dlite922 Nov 07 '17 at 23:19
  • It can only be the first result if someone created such a matrix. No one has. The requirements of a particular Scala version is listed on the download page for that Scala version. E.g. [Scala 2.11.0](https://www.scala-lang.org/download/2.11.0.html) says *"First, make sure you have the **Java 8 JDK** installed."* As such, your desire to "run any version of scala on jdk 1.7" is obviously impossible. – Andreas Nov 07 '17 at 23:25
  • wait a minute. Even Scala 2.10.6 page still says download JDK 1.8. So much for that comment. Looks like that page is a template and no matter which version of scala you want, it still says jdk 8. even if JDK 8 wasn't around when that version of scala was released. This answer just confuses the hell out of noobs. – dlite922 Nov 07 '17 at 23:43
  • 1
    In case someone else stumbles on the question: the problem was not running SBT or Scala (versions before Scala 2.12 and SBT 1.0 work fine). The problem was the Jetty plugin. – Alexey Romanov Nov 08 '17 at 07:09

1 Answers1

7

Scala 2.12 requires a Java 8 JVM and library. You will either have to use a current version of Java or an outdated version of Scala.

Traits now compile to interfaces with default methods, and Scala lambdas use the same encoding as Java 8 lambdas do. Java 8 lambdas are mostly a library feature and could be backported, but method implementations in interfaces are a backwards-incompatible change to the bytecode language.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • Can I install Scala 2.11 using SBT 0.13? – dlite922 Nov 07 '17 at 20:50
  • 1
    @dlite922 Yes. Just set `scalaVersion := "2.11.11"` in your _SBT_ build file. – Mike Allen Nov 07 '17 at 21:57
  • I have `2.11.12` and no luck. sbt still fails with major minor error. It wants jdk1.8 and I don't know how to tell it to not use it. I have intelliJ configured to have jdk1.7 and it shows the same error. I run clean and destroy target directories but it gets recreated. I don't know what is telling the command line and intellij to use 1.8. Its a simple hello world web-app plugin app. Nothing fancy. Created from this link: https://earldouglas.com/posts/xwp-template.html – dlite922 Nov 07 '17 at 23:05