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"html
organization := "com.lujinhong"java
version := "0.0.1"git
sbtPlugin := truegithub
scalaVersion := "2.10.5"eclipse
(二)轉爲eclipse能夠導入的項目maven
使用了這個插件https://github.com/typesafehub/sbteclipseui
一、在~/.sbt/0.13/plugins/plugins.sbt中輸入如下內容:url
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0」)spa
二、生成eclipse相關的文件插件
sbt eclipse
此時就生成了.project文件
三、在eclipse中導入項目便可
(三)建立scala文件
一、在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"); } }
二、運行項目
$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吧。