Play framework 2.0 のアプリを Eclipse でデバッグする方法

Play framework 2.0 で作成した Web アプリを Eclipse 上でデバッグする方法をご紹介します。

準備

まず、play eclipsify を実行し、Eclipse 用のプロジェクトファイルを生成します。

Eclipse 用プロジェクトファイル作成
> play eclipsify

次に、このプロジェクトファイルを Eclipse に import しておきます。*1

デバッグ

Eclipseデバッグする手順は以下のようになります。

  1. デバッグモードで Play アプリケーションを起動
  2. Eclipse からリモートデバッグ

まず、play debug run を実行し、デバッグモードで Play アプリケーションを起動しておきます。

デバッグモードで Play アプリケーションを起動
> play debug run

Listening for transport dt_socket at address: 9999
[info] Loading project definition from ・・・\sampleApp\project
[info] Set current project to sampleApp (in build file:/・・・/sampleApp/)

--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on port 9000...

(Server started, use Ctrl+D to stop and go back to the console...)

ここで出力された "Listening for transport dt_socket at address: 9999" の 9999 がデバッグ接続用のポート番号となりますので、Eclipse からこの 9999 へ接続してリモートデバッグします。


具体的には、Eclipse の Debug Configurations 画面を開き*2、「Remote Java Application」にデバッグ設定を追加します。

Project を選択し「Port」欄に 9999 を入力して「Debug」ボタンを押下すればリモートデバッグが開始されます。

Eclipse リモートデバッグ設定例


後は、適当な場所にブレークポイントを設定し、http://localhost:9000/ などへアクセスすれば Eclipse 上でデバッグが開始されます。

なお、Disconnect を実施すると*3Eclipse のリモートデバッグが終了します。

*1:Eclipse のメニュー「File」->「Import...」で General の Existing Projects into Workspace を選択してインポートします

*2:Eclipse のメニュー「Run」->「Debug Configurations...」

*3:Eclipse のメニュー「Run」->「Disconnect」