Reputation: 1918
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.
[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.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 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.
$ 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.
$ 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.
Upvotes: 26
Views: 18146
Reputation: 11
I encountered the same proble with CentOS-7.6, here is my solution:
vim /etc/profile
in command line, check your Environment variable to find the jdk version, change it to jdk-1.8. Save and quit safely.
example picture/usr/sbin/alternatives --config java
, choose version-1.8./usr/sbin/alternatives --config javac
, also choose version-1.8.source /etc/profile
to make the settings work.By doing the four steps, I was able to run command sbt again without orror.sbt picture
Upvotes: 1
Reputation: 1918
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).
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.
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.
sudo update-alternatives --config java
Once I installed openjdk-8-jre
and adjusted the default Java version in the system, the sbt run
command ran without any issue.
Upvotes: 27
Reputation: 1953
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 here for Oracle), which for me was 8u152. I then corrected my path entry to
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 -version
indeed returned 1.8.0_152 (make sure to open a fresh terminal - an already open one will remember the old path).
And then sbt run
worked. (Again remembering to do this from a fresh terminal so path is fresh.)
Upvotes: 0
Reputation: 131
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.
Reason: My installed java version was 8. But on my Terminal the version I was using was 7.
Fix: I updated the java version to the newest version and then it worked.
Upvotes: 1