ScalaでWeb開発 (3) Liftのホットデプロイ

2010-11-23

ScalaでWeb開発 (3) Liftのホットデプロイ

今回も、assemblaの公式wikiを参考に作業 http://www.assembla.com/wiki/show/liftweb/Using_Maven

1. 普通のやり方

まずは、jettyを起動して

1
mvn jetty:run

もう一個ターミナル開いて、continuous compileを起動。

1
2
3
4
5
6
$ mvn scala:cc
[INFO] Scanning for projects...
-------------------------------------------------------------
          中略
-------------------------------------------------------------
[INFO] wait for files to compile...

これで、もう一個ターミナル開いて、scalaのコードをちょっぴり変更。 ファイルをセーブすると・・・

1
2
3
4
5
[INFO] Compiling 2 source files to /sample_maven/lift_blank/target/classes at 120834648
[INFO] Could not connect to compilation daemon.
[INFO] prepare-compile in 0 s
[INFO] compile in 3 s
[INFO] wait for files to compile...

コンパイルは自動で走る。jetty側はscanIntervalSecondsで設定した間隔で更新がかかる。 jetty側のログはこんな感じ

1
2
3
4
5
6
7
8
9
10
11
12
13
[INFO] restarting org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@1424b{/,/sample_maven/lift_blank/src/main/webapp}
[INFO] Webapp source directory = /sample_maven/lift_blank/src/main/webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = /sample_maven/lift_blank/target/classes
[INFO] Context path = /
[INFO] Tmp directory = determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = /sample_maven/lift_blank/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = /sample_maven/lift_blank/src/main/webapp
2010-11-23 12:39:21.590:INFO::No Transaction manager found - if your webapp requires one, please configure one.
ERROR - Failed to find a properties file (but properties were accessed). Searched: /xxxxx/xxxxx.propsprops, /props/xxxx.propsprops, /props/xxxx-desktop.propsprops, /props/default.propsprops, /xxx.xxx-desktop.propsprops, /xxx.propsprops, /xxx-desktop.propsprops, /default.propsprops
[INFO] Restart completed at Tue Nov 23 12:39:24 JST 2010

微妙にエラー出てるな・・・。Σ(゜д゜) !? とりあえず、画面は更新が反映されていたのでOK なんか、お手軽だけどscanIntervalSecondsを待たなきゃいけないのが微妙。    

2. JRebelを使ったホットデプロイ

こちらも公式サイトのノウハウをなぞーる。 Zero TurnaroundlからJRebelのライセンスをゲット。(Scala開発者ライセンスはフリー) ※右側のGet JRebel For Freeってやつね。 必要事項を3つほど入力すると、あっけなくライセンスファイルがメールが送られてくる。   次に、公式サイトで必要事項を記入して、フリー版をzipアーカイブでダウンロード。 解凍して、適当な場所に配置。jrebel.jarと同じディレクトリにメールで送られてきた開発者用ライセンスを置いたら、準備完了。   あとは、mvn起動時のオプションを設定して、jrebelを読み込んでやればいい。

1
export MAVEN_OPTS="-noverify -javaagent:/xxxxxxx/jrebel/jrebel.jar"

jrebelは、コンパイルを検知してjetty側の再読み込みをさせる。 なので、やっぱり別ターミナルで下のコマンドを実行しておく。

1
mvn scala:cc

Liftのソースを適当にいじったら、まずscala:ccでコンパイルがかかって、次にJRebelで再読み込みが行われて、 無事に更新が反映された。 scanIntervalSecondsを短くしておけば、JRebelいらなくね?という気もしないでもないが・・・。 何かしらJRebelには良いことがあるのだろうきっと。もう少し調べてみよう。 いずれにしろ、liftのホットデプロイという当初の目的は達成。    


2010/12/7 追記

jrebelを使う場合は、pom.xml内のscanIntervalSecondsを0にセットして無効化。

1
2
3
4
5
6
org.mortbay.jetty
maven-jetty-plugin
6.1.25

/
0