1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Scala Play アプリケーションを Eclipse で開発する

Last updated at Posted at 2015-05-10

Play をインストールして、作成した Play プロジェクトを Eclipse にインポートさせてみます。

環境

  • Mac OSX 10.10.2
  • Scala 2.11.6
  • JDK 1.8.0_45

Eclipse をダウンロード

Eclipse が無い場合は公式のダウンロードページから入手してください。
今回は Eclipse IDE for Eclipse Committers 4.4.2 を使います。

ダウンロードが完了したら、解凍して適当なディレクトリに置いておきましょう。

Play をインストール

正確には Typesafe Activator というアプリケーションをインストールします。
この Activator を使うと簡単に Play アプリケーションを作成できます。

Typesafe のダウンロードページから入手して、こちらも解凍して適当なディレクトリに置いておきましょう。

また、このタイミングで activator のパスを通して置くと良いです。

$ cat << EOS >> ~/.bash_profile
> 
> # Setting PATH for typesafe-activator
> export PATH=\$PATH:/path/to/activator
> 
> EOS
$ source ~/.bash_profile

$ activator -help とコマンドを打って activator のヘルプが出てくれば完了です。

Play アプリケーションの作成

activator を使って早速 Play アプリケーションを作成してみます。

$ activator new sample-app play-scala

このコマンドで、sample-app という名前の play-scala アプリケーションが作成されます。(sample-app というディレクトリが作成されます)
コマンドが実行し終わったら、Play コンソールを立ち上げてみます。

$ cd sample-app
$ activator
...
[sample-app] $

ログが延々と出ると思いますが、最後に [sample-app] $ と表示されたら成功です。
試しにアプリケーションを起動してみましょう。

[sample-app] $ run
...
--- (Running the application, auto-reloading is enabled) ---

[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

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

こちらも延々とログが出た後に、(Server started, use Ctrl+D to stop and go back to the console...) と表示されたら準備完了です。
ブラウザで http://localhost:9000/ にアクセスして、「Your new application is ready.」と表示されることを確認しましょう。

Play コンソールに戻るときは Ctrl+D を押します。

Eclipse にインポート

Play コンソール上で eclipse と打ち、Eclipse にインポートする際に必要な設定ファイルを生成します。

[sample-app] $ eclipse
[info] About to create Eclipse project files for your project(s).
[info] Successfully created Eclipse project files for project(s):
[info] sample-app

次に、Eclipse を起動してメニューから File -> Import を選択します。
ダイアログが表示されたら Existing Projects into Workspace を選択します。
次のダイアログの Select root directory に先ほど作成した Play アプリケーションのディレクトリを指定すると、Projectssample-app が表示されますので、これにチェックをいれて Finish を押します。

Scala プラグインのインストール

素のままの Eclipse では Scala のソースコードを認識してくれないため、Scala IDE for Eclipse というプラグインをいれます。
コチラのページからダウンロード先の URL を確認します。今回利用する Eclipse は Luna なので、http://download.scala-ide.org/sdk/lithium/e44/scala211/stable/site を使います。

Eclipse のメニューから Help -> Install New Software... を選択して、Wordk with の欄に先ほどの URL をコピペします。
Add ボタンを押してしばらく待つといくつかプラグインが出てきますので、ひとまず Scala IDE for Eclipse のみを選択して次に進みます。
後は支持に従って進めていけば、インストーラが完了します。

以上で、Eclipse で Scala Play アプリケーションを開発する環境が整いました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?