Reputation: 1044
I'm going through course on Coursera about scala, and they have assignments for me to do. I downloaded project and there is build.sbt
in it. I tried with sbt
command in terminal, Eclipse and Idea, nothing works. Message in terminal says:
[info] Compiling 8 Scala sources to /Users/(Path to project)/project/target/scala-2.9.2/sbt-0.12/classes...
[error] error while loading CharSequence, class file '/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/rt.jar(java/lang/CharSequence.class)' is broken
[error] (bad constant pool tag 18 at byte 10)
[error] error while loading Comparator, class file '/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/rt.jar(java/util/Comparator.class)' is broken
[error] (bad constant pool tag 18 at byte 20)
[error] error while loading AnnotatedElement, class file '/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/rt.jar(java/lang/reflect/AnnotatedElement.class)' is broken
[error] (bad constant pool tag 18 at byte 76)
[error] /Users/(Path to project)/project/ScalaTestRunner.scala:66: overloaded method value replace with alternatives:
[error] (java.lang.CharSequence,java.lang.CharSequence)java.lang.String <and>
[error] (Char,Char)java.lang.String
[error] cannot be applied to (java.lang.String, java.lang.String)
[error] private def runPathString(file: File) = file.getAbsolutePath().replace(" ", "\\ ")
[error] ^
[error] four errors found
[error] (compile:compile) Compilation failed
As I understand sbt 0.12
using scala 2.9.2
, that doesn't handle Java 1.8 correctly. Of course, downgrading java works, but it's not a solution, because I need Java 1.8. I have installed latest sbt and scala, but I think this project has his own sbt, or something. So, what I need is upgrade sbt or downgrade java specifically for this project. Second is more preferred, because I'm afraid upgrading sbt can result my work to fail on their servers. I'm a very newbee at this so, if I said something very stupid, sorry.
Upvotes: 1
Views: 1635
Reputation: 190759
Another directory you might need to look into is the project directory. There you may find build.properites
file that specifies the version of sbt and Scala. When it has older version that does not work well with the newer Java installation, you can have the error messages.
Upvotes: 1
Reputation: 1044
May be it will help somebody, you can also add scalaVersion := "2.11.6"
to your build.sbt
. Not tested by me, but it is stated in official doc here.
Upvotes: 0
Reputation: 6102
Another way to get sbt
to use a different version of Java is to create a .sbtopts
file at the root of the project containing:
-java-home
/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
for whatever your Java 7 version is. Note: must be on separate lines.
Upvotes: 1
Reputation: 1044
Heh, that what was actually very easy, if you know what to do. Just create .javaversion
file in project directory (or above, as I understand, it searches first in dirs tree) and fill it with oracle64-1.7.0.76
, or any you want. Also, there is nice plugin to make it even more easy.
Upvotes: 0