如何运行“sbt hello, world”?

2024-03-30

我正在尝试了解 Scala/SBT 并正在浏览http://www.scala-sbt.org/0.13/docs/Hello.html http://www.scala-sbt.org/0.13/docs/Hello.html

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

在第二步“运行您的应用程序”中,轮子脱落了。

$ 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 plugin.

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

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

把这个放进去Hello.scala

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

In 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 https://github.com/sbt/sbt-fresh效果很好。如果您对 Scala 和 SBT 完全陌生,上面的代码和构建设置应该可以帮助您入门。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何运行“sbt hello, world”? 的相关文章

随机推荐