gpt4 book ai didi

scala - 如何让 "sbt hello, world"运行?

转载 作者:行者123 更新时间:2023-12-01 09:05:03 25 4
gpt4 key购买 nike

我正试图获得有关 Scala/SBT 的线索,并且正在遍历 http://www.scala-sbt.org/0.13/docs/Hello.html

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

在第 2 步“运行您的应用”时,轮子脱落了。

$ 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 的输出在菜鸟眼中是希腊语...

...
[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
...

我偏离了轨道,在杂草丛中寻找线索。

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

$ 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”在我的开发箱上运行?

最佳答案

这里有一个不用 sbt new 插件的方法。

在目录 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 完全陌生,上面的代码和build设置应该可以帮助您入门。

关于scala - 如何让 "sbt hello, world"运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42707703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com