Scala sbt 运行-“不支持的major.minor 版本52.0”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39197422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Scala sbt run - "Unsupported major.minor version 52.0"
提问by sbbs
Things run without any problem when I work on IntelliJ, but when I try to compile and run my Scala code in the command line (with sbt run) the following error message pops up.
当我在 IntelliJ 上工作时,事情运行没有任何问题,但是当我尝试在命令行中编译和运行我的 Scala 代码(使用sbt run)时,会弹出以下错误消息。
[error] (run-main-0) java.lang.UnsupportedClassVersionError: akka/event/LogSource : Unsupported major.minor version 52.0
java.lang.UnsupportedClassVersionError: akka/event/LogSource : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access0(URLClassLoader.java:71)
at java.net.URLClassLoader.run(URLClassLoader.java:361)
at java.net.URLClassLoader.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 java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2625)
at java.lang.Class.getMethod0(Class.java:2866)
at java.lang.Class.getMethod(Class.java:1676)
I'm using Ubuntu 14.04 LTS.
我正在使用 Ubuntu 14.04 LTS。
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
And my Scala version is 2.9.2.
我的 Scala 版本是 2.9.2。
$ scalac -version
Scala compiler version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL
I barely started learning Scala a few weeks ago, so if anyone could provide some advice on what I should look into, it would be greatly appreciated.
几周前我才刚刚开始学习 Scala,所以如果有人能就我应该研究的内容提供一些建议,我将不胜感激。
回答by sbbs
It turned out that there was a mismatch in the JRE version. In the IntelliJ project settings the project SDK was set to be Java 1.8 (on my local machine), whereas JRE 1.7 was installed on the Ubuntu system (an EC2 instance).
原来是JRE版本不匹配。在 IntelliJ 项目设置中,项目 SDK 设置为 Java 1.8(在我的本地机器上),而 JRE 1.7 安装在 Ubuntu 系统(EC2 实例)上。
In Ubuntu 14.04, the OpenJDK 1.8 is not available by default so the following repository must be added manually. Then the OpenJDK can be installed.
在 Ubuntu 14.04 中,默认情况下 OpenJDK 1.8 不可用,因此必须手动添加以下存储库。然后就可以安装OpenJDK了。
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jre
The default Java version in the system can be changed by running the following command.
可以通过运行以下命令来更改系统中的默认 Java 版本。
sudo update-alternatives --config java
Once I installed openjdk-8-jreand adjusted the default Java version in the system, the sbt runcommand ran without any issue.
一旦我openjdk-8-jre在系统中安装并调整了默认的 Java 版本,该sbt run命令就可以正常运行了。
回答by Pursuit
I encountered the same proble with CentOS-7.6, here is my solution:
我在 CentOS-7.6 上遇到了同样的问题,这是我的解决方案:
- run
vim /etc/profilein command line, check your Environment variable to find the jdk version, change it to jdk-1.8. Save and quit safely. example picture - run
/usr/sbin/alternatives --config java, choose version-1.8. - run
/usr/sbin/alternatives --config javac, also choose version-1.8. - run
source /etc/profileto make the settings work.
vim /etc/profile在命令行中运行,检查您的环境变量以找到 jdk 版本,将其更改为 jdk-1.8。保存并安全退出。 示例图片- 运行
/usr/sbin/alternatives --config java,选择 version-1.8。 - 运行
/usr/sbin/alternatives --config javac,也选择 version-1.8。 - 运行
source /etc/profile以使设置生效。
By doing the four steps, I was able to run command sbt again without orror.sbt picture
通过执行这四个步骤,我能够再次运行命令 sbt 而不会出现错误。sbt 图片
回答by Iran R
I am using a Mac and trying to learn Scala by following a simple Scala tutorial. I got this error when I am trying to run the app.
我正在使用 Mac 并尝试按照简单的 Scala 教程学习 Scala。当我尝试运行该应用程序时出现此错误。
Reason: My installed java version was 8. But on my Terminal the version I was using was 7.
原因:我安装的 java 版本是 8。但在我的终端上,我使用的版本是 7。
Fix: I updated the java version to the newest version and then it worked.
修复:我将 java 版本更新到最新版本,然后它就可以工作了。
回答by Ak S
Update to correct java version and compile again. It should work fine
更新以更正 java 版本并再次编译。它应该工作正常
回答by thund
I suddenly started getting this error on Windows 10. Turned out my path had somehow reverted to point to an old version of the java jdk. To be thorough, I first upgraded to the latest jdk (from herefor Oracle), which for me was 8u152. I then corrected my path entry to
我突然开始在 Windows 10 上收到此错误。结果我的路径以某种方式恢复为指向旧版本的 java jdk。为了彻底,我首先升级到最新的 jdk(从这里到 Oracle),对我来说是 8u152。然后我更正了我的路径条目
c:\Program Files\Java\jdk1.8.0_152\bin
(This would be a little different for the 32 bit version.) I then verified that javac -versionindeed returned 1.8.0_152 (make sure to open a fresh terminal - an already open one will remember the old path).
(对于 32 位版本,这会有点不同。)然后我验证javac -version确实返回了 1.8.0_152(确保打开一个新的终端 - 已经打开的终端会记住旧路径)。
And then sbt runworked. (Again remembering to do this from a fresh terminal so path is fresh.)
然后sbt run工作。(再次记住从新终端执行此操作,因此路径是新鲜的。)

