Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala sbt run - "Unsupported major.minor version 52.0"

Tags:

scala

sbt

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.

like image 995
sbbs Avatar asked Aug 29 '16 01:08

sbbs


2 Answers

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.

like image 95
sbbs Avatar answered Sep 28 '22 17:09

sbbs


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.

like image 22
Iran R Avatar answered Sep 28 '22 18:09

Iran R