sbt基础
sbt基礎(chǔ)
@(SCALA)[others]
更詳細(xì)內(nèi)容請見:http://www.scala-sbt.org/0.13/tutorial/Basic-Def.html
或者 http://wenku.baidu.com/link?url=oKjFBumGoaqqUS7CEnTJdgEYK5r7rdsoT6367ZICG7isAtJKd3NRyawqq-seZuUf8jIwRbCojzBwMSRF4Rm4qFKWEWD9JTeUC90_VinJvWC
(一)創(chuàng)建項(xiàng)目
1、先創(chuàng)建一個(gè)目錄,用于放置目錄 中的所有內(nèi)容,如
mkdir sbtdemo
2、創(chuàng)建相關(guān)的目錄
吐槽一下,好懷念maven,幫你直接生成,尤其是eclipse中的new maven project
據(jù)說sbt也是可以的,使用一個(gè)叫做giter8的插件,但好麻煩,有興趣的可以試一下
3、在build.sbt中輸入內(nèi)容:
name := "sbtdemo"organization := "com.lujinhong"version := "0.0.1"sbtPlugin := truescalaVersion := "2.10.5"(二)轉(zhuǎn)為eclipse可以導(dǎo)入的項(xiàng)目
使用了這個(gè)插件https://github.com/typesafehub/sbteclipse
1、在~/.sbt/0.13/plugins/plugins.sbt中輸入以下內(nèi)容:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0”)2、生成eclipse相關(guān)的文件
sbt eclipse
此時(shí)就生成了.project文件
3、在eclipse中導(dǎo)入項(xiàng)目即可
(三)創(chuàng)建scala文件
1、在src/main/scala中創(chuàng)建SbtDemo.scala,內(nèi)容如下:
object SbtDemo {
def main(args: Array[String]) = {
val demo = new Demo
demo.printHello
}
}
class Demo{
def printHello() = {
print(“Hello World”);
}
}
2、運(yùn)行項(xiàng)目
$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 SbtDemoHello World[success] Total time: 26 s, completed 2015-7-14 18:48:373、或者打包項(xiàng)目:
sbt clean package
此時(shí)生成了./target/scala-2.10/sbt-0.13/sbtdemo-0.0.1.jar文件
(四)添加依賴
在built.sbt中添加以下內(nèi)容
重新編譯即可
依賴的內(nèi)容與maven類似,也可以通過maven repository查詢
另外,好消息:使用Idea一切搞定,壞消息,sbt太慢太慢了,根本無法接受,國內(nèi)的鏡像也很少了,還是先用maven吧。
總結(jié)
- 上一篇: linux常用工具命令
- 下一篇: 使用github pages创建博客