本文介绍了我如何获得“sbt hello, world"?跑步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取有关 Scala/SBT 的线索并且正在浏览 http://www.scala-sbt.org/0.13/docs/Hello.html

I'm trying to get a clue about Scala/SBT and was walking through http://www.scala-sbt.org/0.13/docs/Hello.html

第一步进展顺利...我有一个名为hello"的目录,其中包含 $ sbt new sbt/scala-seed.g8 的结果.

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.

在第 2 步运行您的应用"时,轮子脱落了.

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
>

run last compile:compileIncremental 的输出在菜鸟眼中是希腊文...

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.

我不知道这个版本是否重要,但我是 OSX Sierra,使用 1.8 JDK 和 0.13.13 SBT.这台机器上有一个 Scala 2.12.1.

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.

如何让SBT Hello, World"在我的开发箱上运行?

How do I get the "SBT Hello, World" to run on my dev box?

推荐答案

这是一种无需 sbt new 插件的方法.

Here's a way to do it without the sbt new plugin.

在目录Hello中创建以下目录和文件:

Create the following dirs and file in a directory Hello:

├── build.sbt
└── src
    └── main
        └── scala
            └── Hello.scala

把它放在Hello.scala

object Hello extends App{
  println("Hello")
}

Hello/build.sbt 中添加这一行:

scalaVersion := "2.11.8

使用 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
...

我过去曾与 g8/giterate 模板混合"过结果,但这可能是也可能不是您的问题.我使用过 https://github.com/sbt/sbt-fresh 并且有效出色地.如果您完全不熟悉 Scala 和 SBT,上面的代码和构建设置应该可以帮助您入门.

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.

这篇关于我如何获得“sbt hello, world"?跑步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:19