如何在JDK 1.7中使用Scala? (不支持的major.minor 52.0错误)

时间:2017-11-07 20:24:44

标签: java scala sbt java-7

这个“不支持的major.minor 52.0版本”错误让我疯了。

如何让scala使用jdk 1.7。我的SBT项目需要为1.7,除非我将java_home设置为1.8,否则我无法运行sbt或scala。

我的google foo并不强大,因为这个模糊关键字问题有很多结果。

我是否需要安装不同版本的scala? SBT?

谢谢,

修改详情:

 $ 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)

./项目/ build.sbt

addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "3.0.1")

1 个答案:

答案 0 :(得分:7)

Scala 2.12 requires a Java 8 JVM and library。您将不得不使用当前版本的Java或过时版本的Scala。

Traits现在使用interface方法编译为default,Scala lambdas使用与Java 8 lambdas相同的编码。 Java 8 lambdas are mostly a library feature and could be backported,但接口中的方法实现是对字节码语言的向后不兼容的更改。