Scala Lift, サクっと設定とか

急ピッチで作業してやんよ。

なんでscala?というと、Androidで実行できるとか聞いたので。
決してこのようなページを見つけたからではない。
前置きはめんどくさいので以下。
scalaとは

scalaダウンロード
http://www.scala-lang.org/

StableのMac OS Xを適当な場所に落として環境変数設定

% export SCALA_HOME=/Users/runeleaf/works/scala-2.7.7.final
% export PATH=$PATH:$SCALA_HOME/bin

.zshrcにあとで書いておく。

最近のOSXならナニも考えずにできるはず。

インタプリタ

% scala                                     
Welcome to Scala version 2.7.7.final (Java HotSpot(TM) Client VM, Java 1.5.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala>

scala> println("こんにちわ")
こんにちわ

scala>:quit
%

さくさく次へ。
MavenとLift
scala liftとは

Mavenを使用するのですが、githubにあるliftwebのなかにあったのでそれを落として使います。

% git clone git://github.com/dpp/liftweb.git

落としてきたなかにmvnがあるのでパスを通す

% export PATH=/Users/runeleaf/works/code/git/liftweb/installer/src/apache-maven-2.2.0/bin:$PATH

プロジェクト作成

% mvn archetype:generate -U -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-basic -DarchetypeVersion=1.0 -DgroupId=net.runeleaf.hello -DartifactId=helloliftweb
% mvn jetty:run

ブラウザから下記のアドレスを開く。
http://localhost:8080

上記のオプションだと、

こんなのとか、

こんなフォームとかできてます。

ようやくスタートラインですね。

広告

Ruby, rvmでrubyとかgemとかrakeとかのバージョン切り替え

もうすぐrails3.0もくることなので、そのまえに準備できることはしておこうかなと。
業務アプリをつくっていると、どうしても古いrubyとrailsのバージョンを使用しているプロダクトが存在するため、そういったアプリケーションを保守していくことが大変になります。
だけど!新しくつくるアプリは最新のバージョンでやりたい・・・!
そんなときにrvmで一発切り替えができるのはすごく楽です。

rvmでインストールしたruby(rake,gem)は~/.rvm以下のディレクトリに配置されるようです。

元々のrubyはmacportでインストールしていました。

% which ruby
/opt/local/bin/ruby
% ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9]

gemでインストールするには以下のようにします。

% sudu gem install rvm
Password:
********************************************************************************

  In order to setup rvm for your user's environment you must now run rvm-install.
  rvm-install will be found in your current gems bin directory corresponding to where the gem was installed.

  rvm-install will install the scripts to your user account and append itself to your profiles in order to
  inject the proper rvm functions into your shell so that you can manage multiple rubies.

********************************************************************************
Successfully installed rvm-0.1.8

% rvm-install

更新が頻繁なようなのでgithubからにします。

% git clone git://github.com/wayneeseguin/rvm.git
Initialized empty Git repository in /Users/runeleaf/works/code/git/rvm/.git/
remote: Counting objects: 8827, done.
remote: Compressing objects: 100% (2360/2360), done.
remote: Total 8827 (delta 5613), reused 8327 (delta 5265)
Receiving objects: 100% (8827/8827), 1.29 MiB | 525 KiB/s, done.
Resolving deltas: 100% (5613/5613), done.

% ./install

Installing rvm to /Users/runeleaf/.rvm/ ...
mkdir: /usr/local/bin: Permission denied

rvm - shell scripts that allows a user to manage multiple ruby versions in their own account.

**** NOTICE *************************************************************************************
*  The rubies install path has moved to $rvm_path/rubies/ instead of directly in $rvm_path.     *
*  If you encounter any issues with a ruby your best bet is to 'rvm remove X ; rvm install X'   *
*  Gems are now per interpreter installation instead of per interpreter/version                 *
*  so for example to upgrade an older install of 1.8.6 and preserve gems:                       *
*  rm -rf ~/.rvm/gems/ruby-1.8.6-p383 ;  mv ~/.rvm/gems/ruby/1.8.6 ~/.rvm/gems/ruby-1.8.6-p383  *
*************************************************************************************************


Notes for Darwin ( Mac OS X )


    *  For Snow Leopard be sure to have XCode Tools Version 3.2.1 (1613) or later (there were bugs with the dvd release version).

    *  You should download the latest XCode tools from developer.apple.com. This is necessary since the dvd install for Snow Leopard has bugs.

    *  If you intend on installing MacRuby you must install LLVM first.

    *  If you intend on installing JRuby you must install the JDK.

    *  If you intend on installing IronRuby you must install Mono (version 2.6 or greater is recommended).

RTFM:  http://rvm.beginrescueend.com/

HELP:  http://webchat.freenode.net/?channels=rvm

********************************************************************************

 runeleaf,


Thank you for using rvm. I hope that it makes your work easier and more enjoyable.
If you have any questions, issues and/or ideas for improvement please hop in #rvm on irc.freenode.net and let me know.
My irc nickname is 'wayneeseguin' and I hang out from ~09:00-17:00EST and again from ~21:00EST-~00:00EST.
If I do not respond right away, please hang around after asking your question, I will respond as soon as I am back.

  w⦿‿⦿t!

    ~ Wayne

********************************************************************************

You must now finish the install manually:

1) Place the folowing line at the end of your shell's loading files(.bashrc and then .bash_profile for bash and .zshrc for zsh), after all path/variable settings:

     if [[ -s /Users/runeleaf/.rvm/scripts/rvm ]] ; then source /Users/runeleaf/.rvm/scripts/rvm ; fi

2) Ensure that there is no 'return' from inside the .bashrc file. (otherwise rvm will be prevented from working properly).

3) CLOSE THIS SHELL and open a new one in order to use rvm.

なんかPermission denied??とか。。
とりあえず無視して.zshrcの一番下に以下の一行を加えます。

if [[ -s /Users/runeleaf/.rvm/scripts/rvm ]] ; then source /Users/runeleaf/.rvm/scripts/rvm ; fi

ターミナル開き直します。

% rvm -v

rvm 0.1.8 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]

状況把握

% rvm info

rvm 0.1.8 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]

system:
  uname:        "Darwin runeleaf.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386"
  shell:         "zsh"
  version:     "4.3.4"

ruby:
  interpreter:  "ruby"
  version:      "1.8.7"
  date:         "2008-08-11"
  platform:     "i686-darwin9"
  patchlevel:   "2008-08-11 patchlevel 72"
  full_version: "ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9]"

homes:
  gem:          "'not set'"
  ruby:         "'not set'"

binaries:
  ruby:         "/opt/local/bin/ruby"
  irb:          "/opt/local/bin/irb"
  gem:          "/opt/local/bin/gem"
  rake:         "/opt/local/bin/rake"

environment:
  GEM_HOME:     ""
  GEM_PATH:     ""
  MY_RUBY_HOME: ""
  IRBRC:        ""

インストール出来そうなリストの一覧

% rvm list --all

(ruby-)1.8.0-tv1_8_0
(ruby-)1.8.0-tv1_8_0_preview1
(ruby-)1.8.0-tv1_8_0_preview2
(ruby-)1.8.0-tv1_8_0_preview3
(ruby-)1.8.0-tv1_8_0_preview4
(ruby-)1.8.0-tv1_8_0_preview5
(ruby-)1.8.0-tv1_8_0_preview6
(ruby-)1.8.0-tv1_8_0_preview7
(ruby-)1.8.1-tv1_8_1
(ruby-)1.8.1-tv1_8_1_preview1
(ruby-)1.8.1-tv1_8_1_preview2
(ruby-)1.8.1-tv1_8_1_preview3
(ruby-)1.8.1-tv1_8_1_preview4
(ruby-)1.8.2-tv1_8_2
(ruby-)1.8.2-tv1_8_2_preview1
(ruby-)1.8.2-tv1_8_2_preview2
(ruby-)1.8.2-tv1_8_2_preview3
(ruby-)1.8.2-tv1_8_2_preview4
(ruby-)1.8.3-tv1_8_3
(ruby-)1.8.3-tv1_8_3_preview1
(ruby-)1.8.3-tv1_8_3_preview2
(ruby-)1.8.3-tv1_8_3_preview3
(ruby-)1.8.4-tv1_8_4
(ruby-)1.8.4-tv1_8_4_preview1
(ruby-)1.8.4-tv1_8_4_preview2
(ruby-)1.8.5-tv1_8_5
(ruby-)1.8.5-tv1_8_5_11
(ruby-)1.8.5-tv1_8_5_113
(ruby-)1.8.5-tv1_8_5_114
(ruby-)1.8.5-tv1_8_5_115
(ruby-)1.8.5-tv1_8_5_12
(ruby-)1.8.5-tv1_8_5_2
(ruby-)1.8.5-tv1_8_5_231
(ruby-)1.8.5-tv1_8_5_35
(ruby-)1.8.5-tv1_8_5_52
(ruby-)1.8.5-tv1_8_5_preview1
(ruby-)1.8.5-tv1_8_5_preview2
(ruby-)1.8.5-tv1_8_5_preview3
(ruby-)1.8.5-tv1_8_5_preview4
(ruby-)1.8.5-tv1_8_5_preview5
(ruby-)1.8.6-tv1_8_6
(ruby-)1.8.6-tv1_8_6_110
(ruby-)1.8.6-tv1_8_6_111
(ruby-)1.8.6-tv1_8_6_114
(ruby-)1.8.6-tv1_8_6_230
(ruby-)1.8.6-tv1_8_6_286
(ruby-)1.8.6-tv1_8_6_287
(ruby-)1.8.6-tv1_8_6_36
(ruby-)1.8.6-tv1_8_6_368
(ruby-)1.8.6-tv1_8_6_369
(ruby-)1.8.6-tv1_8_6_383
(ruby-)1.8.6-tv1_8_6_388
(ruby-)1.8.6-tv1_8_6_398
(ruby-)1.8.6-tv1_8_6_399
(ruby-)1.8.6-tv1_8_6_preview1
(ruby-)1.8.6-tv1_8_6_preview2
(ruby-)1.8.6-tv1_8_6_preview3
(ruby-)1.8.7-tv1_8_7
(ruby-)1.8.7-tv1_8_7_160
(ruby-)1.8.7-tv1_8_7_17
(ruby-)1.8.7-tv1_8_7_173
(ruby-)1.8.7-tv1_8_7_174
(ruby-)1.8.7-tv1_8_7_22
(ruby-)1.8.7-tv1_8_7_248
(ruby-)1.8.7-tv1_8_7_249
(ruby-)1.8.7-tv1_8_7_71
(ruby-)1.8.7-tv1_8_7_72
(ruby-)1.8.7-tv1_8_7_preview1
(ruby-)1.8.7-tv1_8_7_preview2
(ruby-)1.8.7-tv1_8_7_preview3
(ruby-)1.8.7-tv1_8_7_preview4
(ruby-)1.9.0-tv1_9_0_0
(ruby-)1.9.0-tv1_9_0_1
(ruby-)1.9.0-tv1_9_0_2
(ruby-)1.9.0-tv1_9_0_3
(ruby-)1.9.0-tv1_9_0_4
(ruby-)1.9.0-tv1_9_0_5
(ruby-)1.9.1-tv1_9_1_0
(ruby-)1.9.1-tv1_9_1_126
(ruby-)1.9.1-tv1_9_1_127
(ruby-)1.9.1-tv1_9_1_128
(ruby-)1.9.1-tv1_9_1_129
(ruby-)1.9.1-tv1_9_1_243
(ruby-)1.9.1-tv1_9_1_376
(ruby-)1.9.1-tv1_9_1_378
(ruby-)1.9.1-tv1_9_1_preview1
(ruby-)1.9.1-tv1_9_1_preview2
(ruby-)1.9.1-tv1_9_1_rc1
(ruby-)1.9.1-tv1_9_1_rc2
(ruby-)1.9.2-tv1_9_2_preview1
(ruby-)1.9.2-tv1_9_2_preview2
(ruby-)1.8.6(-p383)
(ruby-)1.8.6-head
(ruby-)1.8.7(-p248)
(ruby-)1.8.7-head
(ruby-)1.9.1(-p243)
(ruby-)1.9.1(-p376)
(ruby-)1.9.1-head
(ruby-)1.9.2-preview1
jruby-1.2.0
jruby-1.3.0
jruby-1.3.1
jruby(-1.4.0) # the default
jruby-head
rbx(-prc1) # default
rbx-head
ree-1.8.6
ree(-1.8.7) # the default
ree-1.8.6-head
ree-1.8.7-head
maglev(-22725)
mput(-head) # shyouhei head, the default mput
ironruby-0.9.3 # (1.0 RC1)
ironruby-head
macruby(-nightly) # the default macruby
macruby-head # Build from the macruby git repository

エンタープライズが入れられるとか聞いたんだけど、どれだろうか・・reeがそうなのか?

1.9.1を入れてみます。
なんにもいれてない状態。

% echo $PATH
/Developer/SDKs/flex/bin:/Users/runeleaf/works/bin:/Users/runeleaf/works/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql83/bin:/opt/local/apache2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin

インストールされているrubyリスト

% rvm list

   system [ i386 ]

1.9.1をインストール

% rvm install 1.9.1
Installing Ruby from source to: /Users/runeleaf/.rvm/rubies/ruby-1.9.1-p378


Downloading ruby-1.9.1-p378, this may take a while depending on your connection...

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8862k  100 8862k    0     0   982k      0  0:00:09  0:00:09 --:--:-- 1175k

Extracting ruby-1.9.1-p378 ...


Configuring ruby-1.9.1-p378, this may take a while depending on your cpu(s)...


Compiling ruby-1.9.1-p378, this may take a while, depending on your cpu(s)...


Installing ruby-1.9.1-p378


Installation of ruby-1.9.1-p378 is complete.


Updating rubygems for ruby-1.9.1-p378


Installing gems for ruby-1.9.1-p378.


Installing rake


Installation of gems for ruby-1.9.1-p378 is complete.

インストールされているリスト

% rvm list

   ruby-1.9.1-p378 [ i386 ]
   system [ i386 ]

1.9.1を指定する

% rvm use 1.9.1

Now using ruby 1.9.1 p378

% echo $PATH
/Users/runeleaf/.rvm/rubies/ruby-1.9.1-p378/bin:/Users/runeleaf/.rvm/gems/ruby-1.9.1-p378/bin:/Users/runeleaf/.rvm/gems//Users/runeleaf/.rvm/gems/ruby-1.9.1-p378%global/bin:/Users/runeleaf/.rvm/bin:/Developer/SDKs/flex/bin:/Users/runeleaf/works/bin:/Users/runeleaf/works/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql83/bin:/opt/local/apache2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin

% ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin9.8.0]

適当にgem入れます。

% gem install json
% gem list

*** LOCAL GEMS ***

json (1.2.0)
rake (0.8.7)
rubygems-update (1.3.5)

1.8.7も入れます。

% rvm install 1.8.7

Now using ruby 1.8.7 p249

% rvm use 1.8.7 

Now using ruby 1.8.7 p249

% gem list

*** LOCAL GEMS ***

rake (0.8.7)

% ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.8.0]

1.9.1に戻して状況把握

% rvm use 1.9.1
% rvm info

rvm 0.1.8 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]

system:
  uname:        "Darwin runeleaf.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386"
  shell:         "zsh"
  version:     "4.3.4"

ruby:
  interpreter:  "ruby"
  version:      "1.9.1p378"
  date:         "2010-01-10"
  platform:     "i386-darwin9.8.0"
  patchlevel:   "2010-01-10 revision 26273"
  full_version: "ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin9.8.0]"

homes:
  gem:          "/Users/runeleaf/.rvm/gems/ruby-1.9.1-p378"
  ruby:         "/Users/runeleaf/.rvm/rubies/ruby-1.9.1-p378"

binaries:
  ruby:         "/Users/runeleaf/.rvm/rubies/ruby-1.9.1-p378/bin/ruby"
  irb:          "/Users/runeleaf/.rvm/rubies/ruby-1.9.1-p378/bin/irb"
  gem:          "/Users/runeleaf/.rvm/rubies/ruby-1.9.1-p378/bin/gem"
  rake:         "/Users/runeleaf/.rvm/rubies/ruby-1.9.1-p378/bin/rake"

environment:
  GEM_HOME:     "/Users/runeleaf/.rvm/gems/ruby-1.9.1-p378"
  GEM_PATH:     "/Users/runeleaf/.rvm/gems/ruby-1.9.1-p378:/Users/runeleaf/.rvm/gems/ruby-1.9.1-p378%global"
  MY_RUBY_HOME: "/Users/runeleaf/.rvm/rubies/ruby-1.9.1-p378"
  IRBRC:        "/Users/runeleaf/.rvm/rubies/ruby-1.9.1-p378/.irbrc"

おぉぅ・・・