问题
I'm trying to get a clue about Scala/SBT and was walking through http://www.scala-sbt.org/0.13/docs/Hello.html
The first step went well...I've got a directory called "hello" that has the result of $ sbt new sbt/scala-seed.g8
in it.
At the 2nd step, "Running your app", the wheels come off.
$ sbt
[info] Loading project definition from /Users/robert.kuhar/dev/Hello/project
[info] Set current project to Hello (in build file:/Users/robert.kuhar/dev/Hello/)
> run
[info] Compiling 1 Scala source to /Users/robert.kuhar/dev/Hello/target/scala-2.12/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.12.1. Compiling...
[info] Resolving org.scala-sbt#interface;0.13.13 ...
[trace] Stack trace suppressed: run last compile:compileIncremental for the full output.
[error] (compile:compileIncremental) java.lang.reflect.InvocationTargetException
[error] Total time: 1 s, completed Mar 9, 2017 3:34:03 PM
>
The output of the run last compile:compileIncremental
is greek to the eyes of a noobie...
...
[info] Resolving org.scala-sbt#interface;0.13.13 ...
java.lang.VerifyError: Uninitialized object exists on backward branch 209
Exception Details:
Location:
scala/collection/immutable/HashMap$HashTrieMap.split()Lscala/collection/immutable/Seq; @249: goto
Reason:
Error exists in the bytecode
...
I'm off the track, in the weeds, and in search of a clue.
I don't know if any of this version stuff matters, but I'm OSX Sierra with a 1.8 JDK and 0.13.13 SBT. There is a Scala 2.12.1 on this machine.
$ sbt sbtVersion
[info] Loading project definition from /Users/robert.kuhar/dev/Hello/project
[info] Set current project to Hello (in build file:/Users/robert.kuhar/dev/Hello/)
[info] 0.13.13
$ java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
$ scala -version
Scala code runner version 2.12.1 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc.
How do I get the "SBT Hello, World" to run on my dev box?
回答1:
Here's a way to do it without the sbt new
plugin.
Create the following dirs and file in a directory Hello
:
├── build.sbt
└── src
└── main
└── scala
└── Hello.scala
Put this in Hello.scala
object Hello extends App{
println("Hello")
}
In Hello/build.sbt
add this line:
scalaVersion := "2.11.8
Run it with run
/tmp/Hello $ sbt [16:40:38]
[info] Loading global plugins from /home/brian/.sbt/0.13/plugins
[info] Set current project to hello (in build file:/tmp/Hello/)
> run
[info] Compiling 1 Scala source to /tmp/Hello/target/scala-2.11/classes...
[info] Running Hello
Hello
...
I've had "mixed" results with the g8/giterate templates in the past but that may or may not be your issue. I've used https://github.com/sbt/sbt-fresh and that worked well. If your completely new to Scala and SBT the above code and build setup should get you started.
来源:https://stackoverflow.com/questions/42707703/how-do-i-get-sbt-hello-world-to-run