Grailsインストール+簡単な認証付きアプリをサックリ作成して動作確認。
いまさらだけど書いてみる
- ここからダウンロード → http://grails.org/Download
ダウンロードページからBinary ZIPあたりをダウンロード
ダウンロードしたzipファイルを解凍
- 環境変数設定
解凍先が/opt/grails-1.0.3の場合
$ export GRAILS_HOME=/opt/grails-1.0.3
- PATHを通す
$ export PATH=$PATH:$GRAILS_HOME/bin
- 動作確認(1)
$ grails Welcome to Grails 1.0.3 - http://grails.org/ Licensed under Apache Standard License 2.0 Grails home is set to: /opt/grails-1.0.3
- 動作確認(2)
$ grails create-app simple ←アプリ作成 ..省略.. [copy] Copying 1 file to /works/tmp/junk/simple [copy] Copying 1 file to /works/tmp/junk/simple [copy] Copying 1 file to /works/tmp/junk/simple [copy] Copying 1 file to /works/tmp/junk/simple [propertyfile] Updating property file: /works/tmp/junk/simple/application.properties Created Grails Application at /works/tmp/junk/simple $ cd simple ←ディレクトリに移動 $ grails create-domain-class message ← ドメインクラス作成 $ tee grails-app/domain/Message.groovy <<EOF ←ドメインクラス編集 class Message { String title String message Date dateCreated Date lastUpdated static constraints = { title(nullable:false) message(maxSize:5000) } } EOF $ grails generate-all Message ←スカッフォルド実行 ..省略.. Generating views for domain class Message ... Generating controller for domain class Message ... Finished generation for domain class Message $ grails run-app ←アプリ起動 ..省略.. 2008-09-15 16:27:49.903:/simple:INFO: Initializing Spring FrameworkServlet 'grails' 2008-09-15 16:27:49.034::INFO: Started SelectChannelConnector@0.0.0.0:8080 Server running. Browse to http://localhost:8080/simple
ブラウザで確認、http://localhost:8080/simple/
- 動作確認(3) 認証を・・
↓ Acegiプラグインインストール $ grails install-plugin http://svn.codehaus.org/grails-plugins/grails-acegi/tags/RELEASE_0_3/grails-acegi-0.3.zip ..省略.. Loading with installed plug-ins: ["acegi"] ... Executing acegi-0.3 plugin post-install script ... Plugin acegi-0.3 installed Plug-in provides the following new scripts: ------------------------------------------ grails create-auth-domains grails generate-manager grails generate-registration grails security-targets $ grails create-auth-domains ← 認証用ドメイン生成 $ grails generate-manager ← 仮の認証用ドメイン管理ページなど生成 $ grails run-app ←アプリ起動
ロールを追加
http://localhost:8080/simple/role/create
ユーザを追加
http://localhost:8080/simple/user/create
権限を追加
http://localhost:8080/simple/requestmap/create
以下のページをみようとすると・・
http://localhost:8080/simple/message
ログインページへ飛ばされます。
http://localhost:8080/simple/login/auth
作成したユーザID&パスワードでログインできます。
Gradleインストール+少し遊んでみる
Gradleで遊んでみた。
なんだかずっとコピペ・・・。
- ここからダウンロード → http://www.gradle.org/
http://dist.codehaus.org/gradle/gradle-0.3-all.zip
ダウンロードしたzipファイルを解凍
- 環境変数設定
解凍先が/opt/gradle-0.3の場合
$ export GRADLE_HOME=/opt/gradle-0.3
- PATHを通す
$ export PATH=$PATH:$GRADLE_HOME/bin
- 動作確認
"gradle -v"で、こんな感じのが出たらOK
$ gradle -v Gradle 0.3 Gradle buildtime: Wednesday, August 20, 2008 11:52:20 PM CEST Groovy 1.5.5 Java 1.5.0_13 JVM 1.5.0_13-119 JVM Vendor: Apple Inc. OS Name: Mac OS X
- 試してみる
ビルドファイル"build.gradle"を作成
//ハローワールド createTask('hello') { println 'ハロー' }
実行!
$ gradle hello Buildfilename: build.gradle ....省略.... ++ Loading Project objects ++ Configuring Project objects Project= : evaluated. ++++ Starting build for primary task 'hello'. Executing: :hello ハロー BUILD SUCCESSFUL Total time: 0.873 secs
デフォルトタスクを指定
defaultTasks "hello" //ハローワールド createTask('hello') { println 'ハロー' }
引数なしで実行!結果は上と同じ.
$ gradle
- いろいろ試してみる。(ソースのみ ※今後詳しく書く)
//デフォルトタスクを(複数)指定 defaultTasks "hello","task2" createTask('hello') { println 'ハロー' } //ダイナミックにタスク定義 4.times { c -> createTask("T_$c") { println "${c}番目のタスク" } } //既存タスクの前に処理を追加したり・・ task('hello').doFirst { println 'helloタスクの前!' } //既存タスクの後に処理を追加したり・・ task('hello').doLast { println 'helloタスクの後!' } //task('')書かなくても、こんな感じにショートカットもできる。 hello.doLast { println 'helloタスクの後の後!' } //DAG (Directed Acyclic Graph 無閉路有向グラフ) message='' createTask('task0') {task, dag -> //task2を持ってるか確認 if(dag.hasTask(':task2')){ message = 'task2を通ったよ' }else{ message = '(wow)' } println message } //task1→task0に依存 createTask('task1', dependsOn: 'task0') { println 'task1実行' } //task2→task1に依存なので更にtask0も依存 createTask('task2', dependsOn: 'task1') { println 'task2実行' }