I would like to install either OpenJDK 8 or Oracle JDK 8 along with Scala using Nix.
I started by installing the Oracle JDK directly. Then I installed scala via Nix by running nix-env -i scala. This completed.
However, running scalac fails:
% scala
Exception in thread "main" java.lang.UnsupportedClassVersionError: scala/tools/nsc/MainGenericRunner : Unsupported major.minor version 52.0
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1070)
at java.lang.ClassLoader.loadClass(ClassLoader.java:414)
at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
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)
I do have JAVA_HOME set:
% echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
To reiterate, I want to install Scala via Nix. I'm like to learn one or more ways to do it. Some notes:
I'm happy to learn more about how Nix packages work if needed.
I haven't gotten a clear, authoritative explanation of how to install the JDK via Nix on macOS. This seems to be a key part of the story.
First, I uninstalled scala with nix-env --uninstall scala.
Then I updated my ~/.nixpkgs/config.nix to include:
{
packageOverrides = pkgs: {
scala = pkgs.scala.override {
jre = pkgs.jre8;
};
};
}
Then I reinstalled scala with nix-env -i scala. Presto!
Update 1: Changed jre = pkgs.openjdk8 to jre = pkgs.jre8.
Update 2: I filed an issue with nixpkgs at https://github.com/NixOS/nixpkgs/issues/22439
Related
I am a bit confused right now. I have installed IntelliJ and the Scala SDK using the installation wizard provided by IntelliJ. I selected the latest version 2.11.8 but were not able to run it in the terminal.
After that I ran
sudo apt-get install scala
which is apparently version 2.9.2
scala -version
Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL
It appears that I now have installed scala under
/home/<user>/.ivy2/cache
(which comes from IntelliJ and has version 2.11.8) and also
whereis scala
scala: /usr/bin/scala /usr/bin/X11/scala /usr/share/man/man1/scala.1.gz
which comes from the package manager and hast version 2.9.2.
How would I clean up this mess?
This is not really a mess. It's perfectly possible to install a system-wide Scala and one based on your projects. The system-wide one really makes little sense except for you to run shell scripts using scala script.scala. You can also see that those Debian and Ubuntu packages are horribly outdated.
Since Scala is not an end-user application but a compiler or library required by specific project builds, one usually does not need and/or use a global installation. When you build a project using sbt or IntelliJ, your project can freely choose the Scala version it wants to use, whether that's 2.9.2, 2.10.x, 2.11.x or 2.12.0-Milestone... And therefore, these installations are all kept concurrently in a cache such as the Ivy cache you are seeing from IntelliJ/sbt.
$ ls -la ~/.ivy2/cache/org.scala-lang/scala-compiler/jars/
... scala-compiler-2.10.0.jar
... scala-compiler-2.10.2.jar
... scala-compiler-2.10.3.jar
... scala-compiler-2.10.4.jar
... scala-compiler-2.10.5.jar
... scala-compiler-2.10.6.jar
... scala-compiler-2.11.0.jar
... scala-compiler-2.11.1.jar
... scala-compiler-2.11.2.jar
... scala-compiler-2.11.5.jar
... scala-compiler-2.11.6.jar
... scala-compiler-2.11.7.jar
... scala-compiler-2.11.8.jar
... scala-compiler-2.12.0-M2.jar
... scala-compiler-2.12.0-M3.jar
... scala-compiler-2.7.3.jar
... scala-compiler-2.8.0.jar
... scala-compiler-2.8.2.jar
... scala-compiler-2.9.0.jar
... scala-compiler-2.9.2.jar
If you want a global installation because you want to run scripts without setting up a minimal sbt project, I recommend not to use apt (you can uninstall scala again) but simply download the latest version from http://scala-lang.org/download/ - I'm not aware of any .deb package depending on a .deb Scala installation.
I have created new Play + Scala project using latest typesafe activator and when trying to import in IntelliJ IDE I was getting below error,
info] Loading project definition from E:\Personal\Scala Workspace\DeployZip\project
E:\Personal\Scala Workspace\DeployZip\build.sbt:18: error: not found: value routesGenerator
routesGenerator := InjectedRoutesGenerator
^
[error] Type error in expression
Consult IDE log for more details (Help | Show Log)
What are the possible reasons for this error?
I have installed jdk 1.8 and now I am able to create project successfully without any error.
But when I tried to run play application using
activator run
I was getting below error now,
java.lang.UnsupportedClassVersionError: org/webjars/WebJarExtractor$Cache : Unsupported major.minor version 51.0
According to this article, I think Unsupported major.minor version 51.0 means that your play application were compiled with Java 1.7 (version 51), but you have Java 1.8 (version 52) installed instead, so you got this error. I'd suggest that you refer to this article for how you could switch between different Java versions.
I was having the error that said Unsupported major.minor version 52.0, and after I installed the latest one (Java 1.8) it was solved.
Hope this helps.
Here is what I've done to solve the issue. Even if you install the java 1.8 it is not sufficient. You have to update the 'path' and 'JAVA_HOME'.
After you install, try to set the jdk1.8 path in the PATH of the environment variables. Also make sure that if you have other versions of the java in the PATH then put the jdk 1.8 path prior to the previous version of java. Or just in case put it in the very beginning of the paths.
I had this same issue. Everything worked after I upgraded Intellij to the latest version (maybe my outdated version used JDK1.7, while activator used 1.8?).
I got a problem when I used sbt to run a spark job, I have finish compile, but when I run the command run, I got the problem below
[error] (run-main-0) java.lang.NoSuchMethodError: scala.collection.immutable.HashSet$.empty()Lscala/collection/immutable/HashSet;
java.lang.NoSuchMethodError: scala.collection.immutable.HashSet$.empty()Lscala/collection/immutable/HashSet;
at akka.actor.ActorCell$.<init>(ActorCell.scala:305)
at akka.actor.ActorCell$.<clinit>(ActorCell.scala)
at akka.actor.RootActorPath.$div(ActorPath.scala:152)
at akka.actor.LocalActorRefProvider.<init>(ActorRefProvider.scala:465)
at akka.remote.RemoteActorRefProvider.<init>(RemoteActorRefProvider.scala:124)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$2.apply(DynamicAccess.scala:78)
at scala.util.Try$.apply(Try.scala:191)
Anyone knows what should I do?
I met with the same error when I used scala-library-2.11 jar But when I replaced it with scala-library-2.10 jar . It runs fine
It is probably caused by using incompatible versions of Scala. When I downgraded from Scala 2.11 to 2.10, I forgot to modify one package version (so one package used 2.11, the rest 2.10), resulting in having the same error.
Note: I only had this problem when using IntelliJ.
If you are getting the error and here because you cannot run Jupiter notebooks with Spark 2.1 and Scala 2.11 below is how I was able to make it work. Assumes you installed Jupiter and toree
Pre-req -
Make sure Docker is running else Make fails.
Make sure gpg is installed else Make fails.
Build steps -
export SPARK_HOME=/Users/<path>/spark-2.1.0-hadoop2.7/
git clone https://github.com/apache/incubator-toree.git
cd incubator-toree
make clean release APACHE_SPARK_VERSION=2.1.0
pip install --upgrade ./dist/toree-pip/toree-0.2.0.dev1.tar.gz
pip freeze |grep toree
jupyter toree install --spark_home=$SPARK_HOME
========================================================================
To Start the notebook -
SPARK_OPTS='--master=local[4]' jupyter notebook
I used these versions and everything works now.
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.6</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>2.3.11</version>
</dependency>
Check whether the scala version you are using corresponds to the precompiled spark version.
The issue could be reproduced with version 2.11.8.
By the moment, no downgrade is required.
Just update scala-library version to 2.12.0.
I've the exactly the same problem and got it fixed by downgrading scala 2.11.8 to 2.10.6.
I've the same issue but where do i alter the scala-library version?
Installation (on Ubuntu 16.04):
sudo apt-get install oracle-java8-installer
wget http://d3kbcqa49mib13.cloudfront.net/spark-2.0.2-bin-hadoop2.7.tgz && tar xvf spark-2.0.2-bin-hadoop2.7.tgz
pip install toree && jupyter toree install
So when I start with a notebook it tells me that I use a different scala version. But I haven't installed anything else.
screenshot + scala version
My spark jars folder contains an scala-library-2.11.8.jar file. But how tell torree to use that (or another) file for scala.
To me both scala versions 2.11 and 2.12 dint work , downgrading to 2.10.3 worked
I've got a Java project versioned by svn and trying to configure the build for linux. On my work computer all works fine and I committed the changes. To both my home computers however I get this error which seems like some trivial setup problem:
Exception in thread "main" java.lang.NoClassDefFoundError: adventure/Adventure
Caused by: java.lang.ClassNotFoundException: adventure.Adventure
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: adventure.Adventure. Program will exit.
Did I forget to add the src to some path? The way it looks in ubuntu is here:
It was committed with Java 7 but on the ubuntu I have only Java 6. Could it still work or do I need to completely harmonize Java versions?
Update
I cleaned the build path and set up the JARs again and I'm going to add the Java 6 JRE since I don't use any Java 7 specific features so it should work if I only get the JRE set up. But I don't know how to add my JRE with linux? I can try also with windows and then maybe I can add a suitable JRE. Now there is a build problem:
Thanks but now I have no JDK which looks like the main problem and just a build problem:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
String cannot be resolved to a type
at adventure.Adventure.main(Adventure.java:74)
My Java version seems well though:
$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (6b24-1.11.1-4ubuntu3)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
The installed JRE is OpenJDK 6 that should work:
My classpath variables look like this
Usually Java projects should be committed without the bin folder (set it to ignore).
It looks like your project was checked-in including the compiled class files from Java 7 with of course can not be loaded by Java 6.
You should proceed as follows:
Open a terminal and change into your project directory
execute svn delete bin
execute svn propset svn:ignore bin .
Does anybody how to do this from whithin Eclipse?
Switch back to Eclipse and execute "Clean" command on the project so that Eclipse re-builds it using your Java version.
But I don't know how to add my JRE with linux?
You surely know Preferences->Java->Installed JREs. Please browse for your Java installations in usr/lib/jvm sub directories.
I installed scala 2.8.0 last night and I seem to be having some issues getting it running. If I type scala at the command prompt it comes up with the following:
> scala
Exception in thread "main" java.lang.NoSuchMethodError: scala.collection.mutable.ListBuffer.toList()Lscala/collection/immutable/List;
at scala.collection.TraversableOnce$class.toList(TraversableOnce.scala:399)
at scala.collection.mutable.ArrayOps.toList(ArrayOps.scala:34)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:33)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Anyone have any ideas? I'm on Windows 7 professional, with Oracle JRE 1.6.0_21
Did you set the SCALA_HOME environment variable to point to the correct directory?
Did you have an older version installed? If that's still on your path then it may be causing problems...
EDIT
Can you paste the contents of your PATH and CLASSPATH environment variables? Perhaps using pastie or pastebin if they're on the large side.
You should also update to Java 1.6.0_22 if at all possible, due to this bug which was present in update 21: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6969236
Turns out this problem occurred because I put the sbt-launch.jar in the lib directory for my scala installation. Once I moved it into another directory scala worked fine.