Intellij ideaとSBTでデバッグするメモ
Intellij ideaでscalaとSBTを使ってデバッグするメモ
OSはScientific linux 6.2、Intellij idea 12の場合です。
- IntellijのSBT Integrationを使いたい場合
Settings->SBT->IDESettingsの、
VM parametersに対して
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005
を追記。
SBT launcherは環境に応じて適宜設定。
- 普通にターミナルからSBTを使いたい場合
/usr/bin/sbtを開いて
declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled"
となっているところを
declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005"
に変更。
- デバッガ接続設定
上記のどちらかを設定した後、IntelliJのRunメニューからEditConfigurationを選択。
緑の+をクリックしてRemoteを選択。
デフォルトで127.0.0.1:5005に接続するようになっています。
後はそのままいじらずにOK押して閉じます。
- 実際につないでみる
SBTを起動してみましょう。以下の様な表示がでるはずです。
$ sbt Detected sbt version 0.12.2 Starting sbt: invoke with -help for other options Listening for transport dt_socket at address: 5005 [info] Loading project definition from /home/xxx/project [info] Set current project to someproject (in build file:/home/xxx/ideaprojects/project/)
Listening for transport dt_socket at address: 5005
に着目しましょう。これでデバッガ接続を待ち受ける様になりました。
あとは先ほど作ったRemoteデバッグ設定をデバッグモードで起動して、REPLとかで実行してみましょう。
いつもどおりにデバッグできるはずです。