sbt教程
touch build.sbtmkdir srcmkdir src/mainmkdir src/main/javamkdir src/main/resourcesmkdir src/main/scalamkdir src/testmkdir src/test/javamkdir src/test/resourcesmkdir src/test/scalamkdir project
name := "sbtdemo"
organization := "com.lujinhong"
version := "0.0.1"
sbtPlugin := true
scalaVersion := "2.10.5"
(二)转为eclipse可以导入的项目
使用了这个插件https://github.com/typesafehub/sbteclipse
1、在~/.sbt/0.13/plugins/plugins.sbt中输入以下内容:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0”)
2、生成eclipse相关的文件
sbt eclipse
此时就生成了.project文件
3、在eclipse中导入项目即可
(三)创建scala文件
1、在src/main/scala中创建SbtDemo.scala,内容如下:
object SbtDemo { def main(args: Array[String]) = { val demo = new Demo demo.printHello } } class Demo{ def printHello() = { print("Hello World"); } }
2、运行项目
$sbt run
[info] Loading global plugins from /Users/liaoliuqing/.sbt/0.13/plugins
[info] Set current project to sbtdemo (in build file:/Users/liaoliuqing/99_Project/1_myCodes/sbtdemo/)
[info] Compiling 1 Scala source to /Users/liaoliuqing/99_Project/1_myCodes/sbtdemo/target/scala-2.10/sbt-0.13/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.5. Compiling...
[info] Compilation completed in 24.361 s
[info] Running SbtDemo
Hello World[success] Total time: 26 s, completed 2015-7-14 18:48:37
// 添加源代码编译或者运行期间使用的依赖
libraryDependencies += "ch.qos.logback" % "logback-core" % "1.0.0"libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.0.0"
// 或者
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-core" % "1.0.0",
"ch.qos.logback" % "logback-classic" % "1.0.0",
...
)
重新编译即可
依赖的内容与maven类似,也可以通过maven repository查询
另外,好消息:使用Idea一切搞定,坏消息,sbt太慢太慢了,根本无法接受,国内的镜像也很少了,还是先用maven吧。