创建工作目录/opt/modules/work/hello
,在该目录创建hw.scala
object Hi {
def main(args: Array[String]) = println("Hi!")
}
运行sbt命令,进入sbt的命令行,执行run命令,即可看到输出。
通过模板创建项目
运行sbt new scala/hello-world.g8
命令,会从Github拉取hello-world的模板。
$ sbt new sbt/scala-seed.g8
....
Minimum Scala build.
name [My Something Project]: hello
Template applied in ./hello
运行应用
$ cd hello
$ sbt
...
> run
...
[info] Compiling 1 Scala source to /xxx/hello/target/scala-2.12/classes...
[info] Running example.Hello
hello
退出sbt shell
> exit
查看hello应用主代码/home/kevin/hello/src/main/scala/Main.scala
object Main extends App {
println("Hello, World!")
}
修改build.sbt,添加依赖
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6"
源代码目录结构
sbt和Maven的源文件目录结构一样。
src/
main/
resources/
<files to include in main jar here>
scala/
<main Scala sources>
java/
<main Java sources>
test/
resources
<files to include in test jar here>
scala/
<test Scala sources>
java/
<test Java sources>
项目构建配置
build.sbt
project/
Build.scala
构建出来的文件(Classes,jars,托管文件,caches和文档)默认在target目录。
.gitignore文件应该包含
target/