Play framework 2.0 のためのブログです。
Comments

基本的な使い方はドキュメントを見るのが早いです。

日本語ドキュメントもあります。

次回からは、自分の躓いたところや、Tipsみたいなのを紹介していきます。


[...]

Categories:
Comments

インストールが完了して、プログラムも動いてブラウザで見れるようになったので、あとはデータベース周りをセッティングします。

Play framework 2.0 では、デフォルトでH2 databaseを使用します。
H2 databaseには、ブラウザ上で使用出来る管理画面が用意されているので、それを利用するところまで解説をします。

まず、
conf/application.conf を開き、以下をコメントアウトします。
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.user=
db.default.password=

そして http://~:9000/ に一度アクセスすると、play が h2dbにアクセスし、ホームディレクトリに .h2.server.properties というファイルが作成されます (作成されなかったら、自分で以下の内容で作成しても問題無いです)



vim ~/.h2.server.properties
#H2 Server Properties
#Tue Oct 09 15:35:58 JST 2012
0=Generic JNDI Data Source|javax.naming.InitialContext|java\:comp/env/jdbc/Test|sa
1=Generic Firebird Server|org.firebirdsql.jdbc.FBDriver|jdbc\:firebirdsql\:localhost\:c\:/temp/firebird/test|sysdba
10=Generic Derby (Server)|org.apache.derby.jdbc.ClientDriver|jdbc\:derby\://localhost\:1527/test;create\=true|sa
11=Generic Derby (Embedded)|org.apache.derby.jdbc.EmbeddedDriver|jdbc\:derby\:test;create\=true|sa
12=Generic H2 (Server)|org.h2.Driver|jdbc\:h2\:tcp\://localhost/~/test|sa
13=Generic H2 (Embedded)|org.h2.Driver|jdbc\:h2\:~/test|sa
2=Generic SQLite|org.sqlite.JDBC|jdbc\:sqlite\:test|sa
3=Generic DB2|COM.ibm.db2.jdbc.net.DB2Driver|jdbc\:db2\://localhost/test|
4=Generic Oracle|oracle.jdbc.driver.OracleDriver|jdbc\:oracle\:thin\:@localhost\:1521\:XE|sa
5=Generic MS SQL Server 2000|com.microsoft.jdbc.sqlserver.SQLServerDriver|jdbc\:microsoft\:sqlserver\://localhost\:1433;DatabaseName\=sqlexpress|sa
6=Generic MS SQL Server 2005|com.microsoft.sqlserver.jdbc.SQLServerDriver|jdbc\:sqlserver\://localhost;DatabaseName\=test|sa
7=Generic PostgreSQL|org.postgresql.Driver|jdbc\:postgresql\:test|
8=Generic MySQL|com.mysql.jdbc.Driver|jdbc\:mysql\://localhost\:3306/test|
9=Generic HSQLDB|org.hsqldb.jdbcDriver|jdbc\:hsqldb\:test;hsqldb.default_table_type\=cached|sa
webAllowOthers=false
webPort=8082
webSSL=false

ここで注目してほしいのが、
webAllowOthers=false
webPort=8082
webSSL=false
の部分。

webAllowOthers を true にすれば、localhost以外のホストからもアクセス可能になります。あとはアクセスするためのポート番号の指定と、httpsを使用するか否かの設定です。

webAllowOthersをtrueにして、
../play
[アプリ名] $ h2-browser
Web Console server running at http://192.168.11.2:8082 (others can connect)
TCP server running at tcp://192.168.11.2:9092 (only local connections)
PG server running at pg://192.168.11.2:5435 (only local connections)

とすれば、設定したポートでブラウザで管理画面にアクセスできます。


webAllowOthers=trueにしておけば、あとは管理画面の[設定]の部分で、ポート番号などの設定をGUIでも行えます。

[...]

Categories:
Comments

今回インストールするバージョンは 2.0.4 です。

① http://www.playframework.org/ より、ソースコードをダウンロードして解凍
# wget http://download.playframework.org/releases/play-2.0.4.zip
# unzip play-2.0.4.zip
# mv play-2.0.4 PLAY_HOME

② playのディレクトリへ移動し、playコマンドでアプリケーション作成
# cd [PLAY_HOME]
# ./play new アプリ名

③ コンパイルと起動
# cd [PLAY_HOME]/アプリ名
# ../play run

これで、http://~~:9000/ にアクセスすればOKです。welcomeページが見れれば成功。


ちなみにwelcomeページはこんなの。

また、コンソールモードも存在する。

# ./play
           _                      _ 
 _ __ |  |   __ _ _  _  |  |
| '_   \|  |/   _'   |   |   |  |_|
|  __/ |_|\____|\__ (_)
|_|                     |__/ 
             
play! 2.0.4, http://www.playframework.org

> Type "help play" or "license" for more information.
> Type "exit" or use Ctrl+D to leave this console.

[アプリ名] $ 



ここで、help play と打てば、使用出来るコマンド一覧がみれます。

help play


Welcome to Play 2.0!

These commands are available:
-----------------------------
classpath                  Display the project classpath.
clean                      Clean all generated files.
compile                    Compile the current application.
console                    Launch the interactive Scala console (use :quit to exit).
dependencies               Display the dependencies summary.
dist                       Construct standalone application package.
exit                       Exit the console.
h2-browser                 Launch the H2 Web browser.
license                    Display licensing informations.
package                    Package your application as a JAR.
play-version               Display the Play version.
publish                    Publish your application in a remote repository.
publish-local              Publish your application in the local repository.
reload                     Reload the current application build file.
run                  Run the current application in DEV mode.
test                       Run Junit tests and/or Specs from the command line
eclipsify                  generate eclipse project file
idea                       generate Intellij IDEA project file
sh         execute a shell command 
start                Start the current application in another JVM in PROD mode.
update                     Update application dependencies.

Type `help` to get the standard sbt help.

[...]

Categories:
Comments


このブログでは、Play framework というJava, ScalaのMVCフレームワークを紹介します。

Play framework は、Java, Scala または両方の言語を使用して開発できるフレームワークである。サイトの情報によると、以下のことが書いてます。


このフレームワークの解説を少しずつしていこうかと思います。基本的に、Javaを利用して解説しますので、よろしくお願いします。





[...]

Categories: