HelloSBT

2章に挑む前に、sbtの設定をする。sbtはSimple Build Tool。

http://code.google.com/p/simple-build-tool/

セットアップ

http://code.google.com/p/simple-build-tool/wiki/Setup を参照。

OutOfMemory対策(追記)

sbt ~jetty-runをしばらく続けていると、OutOfMemoryに陥る。対策は、sbtのシェルスクリプトwindowsならsbt.bat)の内容を、下のようにしよう。

java -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar `dirname $0`/sbt-launch.jar "$@"

参考:http://www.assembla.com/wiki/show/liftweb/Using_SBT

やってみよう

http://d.hatena.ne.jp/katzchang/20101111/p1で作ったhelloliftのディレクトリに移動して、

sbt update
sbt ~jetty-run

する。成功したら↓のようになる。よく「sbt ~jetty:run」と間違えるので注意。

km:hellolift katzchang$ sbt update
Getting Scala 2.7.7 ...
:: retrieving :: org.scala-tools.sbt#boot-scala
	confs: [default]
	2 artifacts copied, 0 already retrieved (9911kB/824ms)
Getting org.scala-tools.sbt sbt_2.7.7 0.7.4 ...
:: retrieving :: org.scala-tools.sbt#boot-app
	confs: [default]
	15 artifacts copied, 0 already retrieved (4096kB/710ms)
[info] Recompiling project definition...
[info] 	  Source analysis: 1 new/modified, 0 indirectly invalidated, 0 removed.
Getting Scala 2.8.0 ...
:: retrieving :: org.scala-tools.sbt#boot-scala
	confs: [default]
	2 artifacts copied, 0 already retrieved (14484kB/1926ms)
[info] Building project hellolift 1.0-SNAPSHOT against Scala 2.8.0
[info]    using LiftProject with sbt 0.7.4 and Scala 2.7.7
[info] 
[info] == update ==
[info] :: retrieving :: hello.lift#hellolift [sync]
[info] 	confs: [default, master, compile, provided, runtime, test, system, sources, javadoc, optional]
[info] 	72 artifacts copied, 0 already retrieved (49319kB/4490ms)
[info] == update ==
[success] Successful.
[info] 
[info] Total time: 14 s, completed 2010/11/11 20:51:25
[info] 
[info] Total session time: 22 s, completed 2010/11/11 20:51:25
[success] Build completed successfully.
km:hellolift katzchang$ sbt ~jetty-run
[info] Building project hellolift 1.0-SNAPSHOT against Scala 2.8.0
[info]    using LiftProject with sbt 0.7.4 and Scala 2.7.7
[info] 
[info] == compile ==
[info]   Source analysis: 4 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling main sources...
[info] Compilation successful.
[info]   Post-analysis: 21 classes.
[info] == compile ==
[info] 
[info] == copy-resources ==
[info] == copy-resources ==
[info] 
[info] == prepare-webapp ==
[info] == prepare-webapp ==
[info] 
[info] == jetty-run ==
log4j:WARN No appenders could be found for logger (org.mortbay.log).
log4j:WARN Please initialize the log4j system properly.
[info] jetty-6.1.25
[info] NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/katzchang/dev/hellolift/lib_managed/scala_2.8.0/test/slf4j-log4j12-1.5.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/katzchang/dev/hellolift/lib_managed/scala_2.8.0/default/slf4j-log4j12-1.5.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/katzchang/dev/hellolift/lib_managed/scala_2.8.0/compile/slf4j-log4j12-1.5.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/katzchang/dev/hellolift/lib_managed/scala_2.8.0/runtime/slf4j-log4j12-1.5.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
[info] Started SelectChannelConnector@0.0.0.0:8080
[info] == jetty-run ==
[success] Successful.
[info] 
[info] Total time: 22 s, completed 2010/11/11 20:53:22
1. Waiting for source changes... (press enter to interrupt)

で、http://localhost:8080/ でおなじみの画面が開く。

jetty-runターゲットに「~」を付けることによって、トリガー実行モードになる。ソースファイルが更新されれば、再度そのタスクを実行する。つまり、 sbt ~compile や sbt ~test もできる。表示通り、Enterでモードを抜けることができる。

sbtはシェルモードも用意されているので、↓のように使うこともできる。

sbt
> update
> ~jetty-run

このとき、Enterでトリガー実行を抜けても、jettyは動き続ける。止めたい場合は↓。

> jetty-stop

他は help や actions コマンドで調べましょう。