IThaiのブログ

IT関連の話題やタイに関する様々なことを書いていきます。

PlayFrameworkのインストール

JavaとScalaのフレームワークである、PlayFrameworkを触ってみました。

簡単に情報収集した感じでは、
・Ruby on Rails、Djangoに近い
・軽量なフレームワークである
・フレームワーク自体がJVMへの動的リロード機能をもつ
・デフォルトでRESTful ・コントローラの全ての開始点はstaticメソッド などがありました。

Playのインストール(1.2系)

以下の記事を参考にしました。

https://www.playframework.com/documentation/ja/1.2.x/home

vagrantで作成したcentOS6.6に環境を作成します。

git cloneでソースをダウンロードします。

# git clone git://github.com/playframework/play.git


antをインストールします。

# yum install ant


antでビルドします。

# cd play/framework
# ant


何かエラーが・・・。

・・・
BUILD FAILED
/home/vagrant/play/framework/build.xml:134: The following error occurred while executing this line:
/home/vagrant/play/modules/docviewer/build.xml:22: Problem creating jar: /home/vagrant/play/modules/docviewer/lib/play-docviewer.jar (No such file or directory) (and the archive is probably corrupt but I could not delete it)


lib/play-docviewer.jarがないと言われる。。

とりあえず、以下の部分をコメントアウトします。

/play/modules/docviewer/build.xml:22


再度、ビルドを実行します。

# ant
BUILD SUCCESSFUL
Total time: 27 seconds



ビルド成功しました。

これでplay実行環境が整いました。試しにサンプルアプリを作成します。

# python play new sampleApp


実行してみます。

# python play run sampleApp


すると、サーバがリクエストを受け付けれる状態になりました。

~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! master-50fb7d0, https://www.playframework.com
~
~ Ctrl+C to stop
~ 
~ using java version "1.7.0_79"
Listening for transport dt_socket at address: 8000
05:52:19,865 INFO  ~ Starting /home/vagrant/play/sampleApp
05:52:22,493 WARN  ~ You're running Play! in DEV mode
05:52:22,739 INFO  ~ Listening for HTTP on port 9000 (Waiting a first request to start) ...
~ Server is up and running


ブラウザから192.168.33.10:9000を叩いてみます。

05:53:27,499 ERROR ~ 

@6mco4chle
Internal Server Error (500) for request GET /

Oops: RuntimeException
An unexpected error occured caused by exception RuntimeException: java.io.FileNotFoundException: /home/vagrant/play/sampleApp/tmp/bytecode/DEV/DocViewerPlugin (No such file or directory)

play.exceptions.UnexpectedException: Unexpected Error
    at play.Play.start(Play.java:566)
    at play.Play.detectChanges(Play.java:640)
    at play.Invoker$Invocation.init(Invoker.java:197)
    at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: /home/vagrant/play/sampleApp/tmp/bytecode/DEV/DocViewerPlugin (No such file or directory)
    at play.classloading.BytecodeCache.cacheBytecode(BytecodeCache.java:115)
    at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:163)
    at play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:78)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at play.plugins.PluginCollection.reloadApplicationPlugins(PluginCollection.java:204)
    at play.Play.start(Play.java:481)
    ... 3 more



と案の定、先ほどコメントアウトしたDocViewerPluginがないというエラーが発生しました。ただ、実行自体はできているので、この問題を解決したら普通に動作しそうです。

先ほどのビルド時のエラー文をもう一度見直すと、docviewerのプラグインを作成しようとして、エラーが出ているようです。作成先のパスに移動して見てみると、libフォルダがないみたいです。docviewer/build.xmlのコメントアウトしたところを戻して、

とりあえず、以下の部分をコメントアウトします。 /play/modules/docviewer/build.xml:22

libフォルダを作成した後、再度ビルドしてみます。

# cd /home/vagrant/play/modules/docviewer/
# mkdir lib
# cd /home/vagrant/play/framework/
# ant


今度は成功しました。

BUILD SUCCESSFUL
Total time: 27 seconds


ブラウザから192.168.33.10:9000を叩いてみます。

f:id:kkv:20150607153506p:plain

無事、成功しました。

Play Framework 2徹底入門

Play Framework 2徹底入門