java:playframework
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
java:playframework [2018/07/20 11:25] – [インストール] taka | java:playframework [2018/09/05 09:52] (現在) – taka | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== Java - Pray Framework ====== | + | ====== Java - Play Framework ====== |
ここでの解説は以下環境を前提にしています。 | ここでの解説は以下環境を前提にしています。 | ||
行 9: | 行 9: | ||
* IntelliJ IDEA Community 2018.1 | * IntelliJ IDEA Community 2018.1 | ||
- | ===== インストール ===== | + | - [[java: |
+ | - [[java: | ||
- | まずビルドツールであるsbtをインストールする。\\ | ||
- | Play Frameworkの作成、起動にはこのsbtを使用する。 | ||
- | |||
- | [[https:// | ||
- | |||
- | MacにHomebrewがあればそちらを使うと便利。 | ||
- | |||
- | <sxh bash> | ||
- | $ brew install sbt@1 | ||
- | </ | ||
- | |||
- | sbtの主なオプション | ||
- | |||
- | ^ オプション | ||
- | | about | バージョンの確認 | ||
- | | new | プロジェクトの作成 | ||
- | | run | プロジェクトの実行 | ||
- | |||
- | ===== インストール(Mac OS X 10.5, 10.6) ===== | ||
- | |||
- | $ ./configure --prefix=/ | ||
- | $ make | ||
- | $ sudo make install | ||
- | |||
- | gem実行時に以下のエラーが出た場合は、LibYAMLをインストールして環境変数を設定した後、Rubyを再度インストールすることで解決する。 | ||
- | |||
- | It seems your ruby installation is missing psych (for YAML output). | ||
- | To eliminate this warning, please install libyaml and reinstall your ruby. | ||
- | |||
- | * **[[http:// | ||
- | |||
- | $ ./configure | ||
- | $ make | ||
- | $ sudo make install | ||
- | |||
- | 環境変数に以下を加える。 | ||
- | |||
- | export DYLD_LIBRARY_PATH=/ | ||
- | | ||
- | ===== インストール(Windows 7 64bit) ===== | ||
- | |||
- | 以下よりRuby 2.0.0-p0 (x64)とDevKit-mingw64-64-4.7.2-20130224-1432-sfx.exeをダウンロード。 | ||
- | |||
- | * **[[http:// | ||
- | |||
- | それぞれRubyはC:/ | ||
- | |||
- | Windowsの環境変数「PATH」に以下を追加。 | ||
- | |||
- | <sxh plain; gutter: false;> | ||
- | C: | ||
- | </ | ||
- | |||
- | DevKitの設定 | ||
- | |||
- | $ cd C:/DevKit | ||
- | $ ruby dk.rb init | ||
- | |||
- | C:/ | ||
- | |||
- | <sxh plain; gutter: false;> | ||
- | # This configuration file contains the absolute path locations of all | ||
- | # installed Rubies to be enhanced to work with the DevKit. This config | ||
- | # file is generated by the 'ruby dk.rb init' step and may be modified | ||
- | # before running the 'ruby dk.rb install' | ||
- | # Rubies that were not automagically discovered, simply add a line below | ||
- | # the triple hyphens with the absolute path to the Ruby root directory. | ||
- | # | ||
- | # Example: | ||
- | # | ||
- | # --- | ||
- | # - C:/ | ||
- | # - C:/ | ||
- | # | ||
- | --- | ||
- | - C:/usr | ||
- | </ | ||
- | |||
- | 以下コマンドを実行して反映。 | ||
- | |||
- | $ ruby dk.rb install | ||
- | |||
- | Gemでriとrdocをインストールしないように設定。\\ | ||
- | C:/ | ||
- | |||
- | <sxh plain; gutter: false;> | ||
- | gem: --no-ri --no-rdoc | ||
- | </ | ||
- | |||
- | gem update --system | ||
- | |||
- | ===== ソースファイルの文字コードを指定する ===== | ||
- | |||
- | <sxh ruby; gutter: false;> | ||
- | # | ||
- | # coding: utf-8 | ||
- | </ | ||
- | |||
- | ===== ファイル/ディレクトリ操作 ===== | ||
- | |||
- | ==== ファイル入出力時の文字コードを指定する ==== | ||
- | |||
- | <sxh ruby; gutter: false;> | ||
- | # | ||
- | # coding: utf-8 | ||
- | |||
- | # 入力 | ||
- | file = File.open(" | ||
- | # 処理 | ||
- | file.close | ||
- | |||
- | # 出力 | ||
- | file = File.open(" | ||
- | # 処理 | ||
- | file.close | ||
- | </ | ||
- | |||
- | ==== 多階層ディレクトリの作成方法 ==== | ||
- | |||
- | <sxh ruby; gutter: false;> | ||
- | # | ||
- | # coding: utf-8 | ||
- | |||
- | path = "/ | ||
- | |||
- | FileUtils.mkpath(path) | ||
- | </ | ||
- | |||
- | === オプション一覧 === | ||
- | |||
- | ^オプション^効果^ | ||
- | |: | ||
- | |: | ||
- | |: | ||
- | |||
- | === オプション使用例 === | ||
- | |||
- | <sxh ruby; gutter: false;> | ||
- | # ディレクトリ作成時のパーミッションを指定通りにするため予めumaskに0を設定 | ||
- | File.umask(0) | ||
- | FileUtils.mkpath(path, | ||
- | </ | ||
- | |||
- | ===== トランスコーディング ===== | ||
- | |||
- | <sxh ruby; gutter: false;> | ||
- | # | ||
- | # coding: utf-8 | ||
- | |||
- | # UTF-8文字列 | ||
- | strings_utf8 = " | ||
- | puts strings_utf8.encoding # => #< | ||
- | |||
- | # SJIS変換 | ||
- | strings_sjis = strings_utf8.encode(" | ||
- | puts strings_sjis.encoding # => #< | ||
- | </ | ||
- | |||
- | <color red> | ||
- | 但し、変換後の文字コードでは使用できない文字が含まれていると、エラーになる。\\ | ||
- | __以下のように不正文字を置換文字列で置換えることで対処できる。__ | ||
- | </ | ||
- | |||
- | <sxh ruby; gutter: false;> | ||
- | # | ||
- | # coding: utf-8 | ||
- | |||
- | # UTF-8文字列 | ||
- | strings_utf8 = " | ||
- | puts strings_utf8.encoding # => #< | ||
- | |||
- | # SJIS変換 | ||
- | strings_sjis = strings_utf8.encode(" | ||
- | puts strings_sjis.encoding # => #< | ||
- | </ | ||
- | |||
- | ===== オブジェクト指向 ===== | ||
- | |||
- | ==== アクセサメソッド ==== | ||
- | |||
- | <sxh ruby; gutter: false;> | ||
- | # ゲッターメソッドを生成 | ||
- | attr_reader | ||
- | # セッターメソッドを生成 | ||
- | attr_writer | ||
- | # ゲッターメソッド/セッターメソッドを生成 | ||
- | attr_accessor :name | ||
- | </ | ||
- | |||
- | <sxh ruby; gutter: false;> | ||
- | # ------------------------------------------------------ | ||
- | class Test | ||
- | # ------------------------------------------------------ | ||
- | |||
- | attr_reader | ||
- | attr_writer | ||
- | attr_accessor :name3 | ||
- | |||
- | # -------------------------------------------------- | ||
- | def initialize(name1, | ||
- | # -------------------------------------------------- | ||
- | @name1 = name1 | ||
- | @name2 = name2 | ||
- | @name3 = name3 | ||
- | end | ||
- | end | ||
- | |||
- | test = Test.new(" | ||
- | |||
- | test.name1 = " | ||
- | puts test.name1 | ||
- | |||
- | test.name2 = " | ||
- | puts test.name2 | ||
- | |||
- | test.name3 = " | ||
- | puts test.name3 | ||
- | |||
- | </ | ||
java/playframework.1532053519.txt.gz · 最終更新: 2018/07/20 11:25 by taka