它實際上只是一個Rails應用程序,你想部署在IIS上,或者它必須是JRuby?如果它只是Ruby on Rails而不是JRuby,那麼here is your step-by-step guide。但如果是JRuby,您希望與IIS合作,請不要再觀望。以下是我遵循的步驟;我的環境是Windows 7 RC,Java 1.6.0_13上的IIS7。
- 首先,我從
http://dist.codehaus.org/jruby/1.3.1/jruby-bin-1.3.1.tar.gz
下載JRuby。
- 然後我解壓到
C:\JRuby
。
- 我將環境變量JRUBY_HOME設置爲
c:\JRuby\jruby-1.3.1
。
- 我將
%JRUBY_HOME%\bin
添加到路徑中。
我會穿過隨後穿插的屏幕抓取步驟。
讓我們運行的JRuby,以確認它已成功安裝:
C:\Users\Vinay>jruby -v
jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.
6.0_13) [x86-java]
OK爲止。讓我們使用JRuby的安裝Rails:
C:\Users\Vinay>gem install json-jruby
C:\Users\Vinay>gem install rails --no-rdoc
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed activerecord-2.3.3
Successfully installed rack-1.0.0
Successfully installed actionpack-2.3.3
Successfully installed actionmailer-2.3.3
Successfully installed activeresource-2.3.3
Successfully installed rails-2.3.3
6 gems installed
Installing ri documentation for activerecord-2.3.3...
Installing ri documentation for rack-1.0.0...
Installing ri documentation for actionpack-2.3.3...
Installing ri documentation for actionmailer-2.3.3...
Installing ri documentation for activeresource-2.3.3...
Installing ri documentation for rails-2.3.3...
讓我們創建一個Rails應用程序稱爲jror
:
C:\Users\Vinay\Projects>rails new jror
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create config/initializers
create config/locales
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create test/fixtures
create test/functional
create test/integration
create test/performance
create test/unit
create vendor
create vendor/plugins
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create Rakefile
create README
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create config/database.yml
create config/routes.rb
create config/locales/en.yml
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/new_rails_defaults.rb
create config/initializers/session_store.rb
create config/environment.rb
create config/boot.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/about
create script/console
create script/dbconsole
create script/destroy
create script/generate
create script/runner
create script/server
create script/plugin
create script/performance/benchmarker
create script/performance/profiler
create test/test_helper.rb
create test/performance/browsing_test.rb
create public/404.html
create public/422.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/robots.txt
create public/images/rails.png
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create public/javascripts/controls.js
create public/javascripts/application.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log
讓我們運行WEBrick
,以確保一切都按預期工作:
C:\Users\Vinay\Projects\jror>jruby script/server
=> Booting WEBrick
=> Rails 2.3.3 application starting on http://0.0.0.0:3000
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2009-07-21 17:51:21] INFO WEBrick 1.3.1
[2009-07-21 17:51:21] INFO ruby 1.8.6 (2009-06-15) [java]
[2009-07-21 17:51:21] INFO WEBrick::HTTPServer#start: pid=2440 port=3000
導航到http://localhost:3000/
並確認您的Rails應用程序出現。果然
,它就在那裏。
接下來就是設置一個機制,將選定的對IIS的請求代理到JRuby。爲此,需要URL重寫器/反向代理。我爲此使用ISAPI Rewrite 3。您可以選擇使用其他工具(例如,Microsoft ISA)。 ISAPI Rewrite 3的價值爲每臺服務器99美元,並附帶45天試用期。
對於ISAPI重寫3,我成立了httpd.conf
配置文件如下:
RewriteEngine on
RewriteBase/
RewriteLog "C:\temp\rewrite.log"
RewriteLogLevel 9
RewriteProxy jror/(.*) http://localhost:3000/$1
表格中的這一代理網址
http://localhost/jror/abc123
到
http://localhost:3000/abc123
所以,現在,我們可以導航到http://localhost/jror/
並查看JRuby提供的請求,但通過IIS:
你猜是什麼:沒有戰爭!直接通過Rails應用程序進行任何更改。
這裏是我的Firebug控制檯顯示該頁面的響應頭截圖:
當然,這更是一個開發設置比生產一個 - 但在生產中使用,你可能會需要使用生產就緒應用服務器,如Glassfish的,這將需要使用那些討厭戰爭;-)
如果當你想將其部署到使用戰爭一個Java應用程序服務器,您可以使用Warbler爲方便您包裝應用程序變成戰爭。
要在Glassfish V3上運行,需要一些額外的步驟。部署和運行Rails應用程序的最快捷方式是使用GlassFish gem,它只包含GlassFish v3內核(Grizzly
)和一些實用程序,因此提供了最小膨脹設置。讓我們安裝gem:
C:\Users\Vinay\Projects\jror>gem install glassfish
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed glassfish-0.9.5-universal-java
1 gem installed
Installing ri documentation for glassfish-0.9.5-universal-java...
Installing RDoc documentation for glassfish-0.9.5-universal-java...
運行在Glassfish的Rails應用程序:
C:\Users\Vinay\Projects>glassfish jror
Starting GlassFish server at: 192.168.0.17:3000 in development environment...
Writing log messages to: jror/log/development.log.
Press Ctrl+C to stop.
正如你所看到的,你Glassfish上運行,但仍然不需要戰爭!除了(我的設置中的httpd.conf
)更改代理以指向Glassfish服務器使用的IP地址和端口之外,IIS端不需要進行任何更改。如果你想整個豬羣安裝完整的Glassfish服務器並運行Rails應用程序,那麼你最好還是關注Glassfish團隊的these instructions。它們包括安裝和運行Glassfish,服務器,部署和取消部署Rails應用程序以及在生產模式下運行應用程序。
下面是您需要爲完整的Glassfish服務器創建war文件。
安裝鶯:
C:\Users\Vinay\Projects>gem install warbler
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed warbler-0.9.13
1 gem installed
Installing ri documentation for warbler-0.9.13...
Installing RDoc documentation for warbler-0.9.13...
運行鶯:
C:\Users\Vinay\Projects\jror>warble
mkdir -p tmp/war/WEB-INF/gems/specifications
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/specifications/rails-2.3.3.gemspec tm
/war/WEB-INF/gems/specifications/rails-2.3.3.gemspec
mkdir -p tmp/war/WEB-INF/gems/gems
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/specifications/rake-0.8.7.gemspec tmp
war/WEB-INF/gems/specifications/rake-0.8.7.gemspec
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/specifications/activesupport-2.3.3.ge
spec tmp/war/WEB-INF/gems/specifications/activesupport-2.3.3.gemspec
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/specifications/activerecord-2.3.3.gem
pec tmp/war/WEB-INF/gems/specifications/activerecord-2.3.3.gemspec
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/specifications/actionpack-2.3.3.gemsp
c tmp/war/WEB-INF/gems/specifications/actionpack-2.3.3.gemspec
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/specifications/rack-1.0.0.gemspec tmp
war/WEB-INF/gems/specifications/rack-1.0.0.gemspec
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/specifications/actionmailer-2.3.3.gem
pec tmp/war/WEB-INF/gems/specifications/actionmailer-2.3.3.gemspec
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/specifications/activeresource-2.3.3.g
mspec tmp/war/WEB-INF/gems/specifications/activeresource-2.3.3.gemspec
mkdir -p tmp/war/WEB-INF/app
mkdir -p tmp/war/WEB-INF/config
mkdir -p tmp/war/WEB-INF/lib
mkdir -p tmp/war/WEB-INF/log
mkdir -p tmp/war/WEB-INF/vendor
mkdir -p tmp/war/WEB-INF/tmp
mkdir -p tmp/war/WEB-INF/app/controllers
mkdir -p tmp/war/WEB-INF/app/helpers
mkdir -p tmp/war/WEB-INF/app/models
mkdir -p tmp/war/WEB-INF/app/views
cp app/controllers/application_controller.rb tmp/war/WEB-INF/app/controllers/ap
lication_controller.rb
cp app/helpers/application_helper.rb tmp/war/WEB-INF/app/helpers/application_he
per.rb
mkdir -p tmp/war/WEB-INF/app/views/layouts
cp config/boot.rb tmp/war/WEB-INF/config/boot.rb
cp config/database.yml tmp/war/WEB-INF/config/database.yml
cp config/environment.rb tmp/war/WEB-INF/config/environment.rb
mkdir -p tmp/war/WEB-INF/config/environments
mkdir -p tmp/war/WEB-INF/config/initializers
mkdir -p tmp/war/WEB-INF/config/locales
cp config/routes.rb tmp/war/WEB-INF/config/routes.rb
cp config/environments/development.rb tmp/war/WEB-INF/config/environments/devel
pment.rb
cp config/environments/production.rb tmp/war/WEB-INF/config/environments/produc
ion.rb
cp config/environments/test.rb tmp/war/WEB-INF/config/environments/test.rb
cp config/initializers/backtrace_silencers.rb tmp/war/WEB-INF/config/initialize
s/backtrace_silencers.rb
cp config/initializers/inflections.rb tmp/war/WEB-INF/config/initializers/infle
tions.rb
cp config/initializers/mime_types.rb tmp/war/WEB-INF/config/initializers/mime_t
pes.rb
cp config/initializers/new_rails_defaults.rb tmp/war/WEB-INF/config/initializer
/new_rails_defaults.rb
cp config/initializers/session_store.rb tmp/war/WEB-INF/config/initializers/ses
ion_store.rb
cp config/locales/en.yml tmp/war/WEB-INF/config/locales/en.yml
mkdir -p tmp/war/WEB-INF/lib/tasks
mkdir -p tmp/war/WEB-INF/vendor/plugins
mkdir -p tmp/war/WEB-INF/tmp/cache
mkdir -p tmp/war/WEB-INF/tmp/pids
mkdir -p tmp/war/WEB-INF/tmp/sessions
mkdir -p tmp/war/WEB-INF/tmp/sockets
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/gems/warbler-0.9.13/lib/jruby-complet
-1.3.0RC1.jar tmp/war/WEB-INF/lib/jruby-complete-1.3.0RC1.jar
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/gems/warbler-0.9.13/lib/jruby-complet
-1.3.0RC1.jar tmp/war/WEB-INF/lib/jruby-complete-1.3.0RC1.jar
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/gems/warbler-0.9.13/lib/jruby-rack-0.
.4.jar tmp/war/WEB-INF/lib/jruby-rack-0.9.4.jar
cp C:/JRuby/jruby-1.3.1/lib/ruby/gems/1.8/gems/warbler-0.9.13/lib/jruby-rack-0.
.4.jar tmp/war/WEB-INF/lib/jruby-rack-0.9.4.jar
cp public/404.html tmp/war/404.html
cp public/422.html tmp/war/422.html
cp public/500.html tmp/war/500.html
cp public/favicon.ico tmp/war/favicon.ico
mkdir -p tmp/war/images
cp public/index.html tmp/war/index.html
mkdir -p tmp/war/javascripts
cp public/robots.txt tmp/war/robots.txt
mkdir -p tmp/war/stylesheets
cp public/images/rails.png tmp/war/images/rails.png
cp public/javascripts/application.js tmp/war/javascripts/application.js
cp public/javascripts/controls.js tmp/war/javascripts/controls.js
cp public/javascripts/dragdrop.js tmp/war/javascripts/dragdrop.js
cp public/javascripts/effects.js tmp/war/javascripts/effects.js
cp public/javascripts/prototype.js tmp/war/javascripts/prototype.js
mkdir -p tmp/war/WEB-INF
jar cf jror.war -C tmp/war .
C:\Users\Vinay\Projects\jror>dir jror.war
Volume in drive C has no label.
Volume Serial Number is 0C8D-1418
Directory of C:\Users\Vinay\Projects\jror
22/07/2009 15:55 13,180,634 jror.war
1 File(s) 13,180,634 bytes
0 Dir(s) 7,730,462,720 bytes free
唷!
我認爲你試圖避免戰爭文件是錯誤的方式。從長遠來看,如果你花一些時間瞭解戰爭檔案,而不是試圖繞過戰爭檔案,那將會變得容易得多。 – 2009-07-21 13:30:47
我已經大幅更新了我的答案,以顯示JRuby和IIS沒有WAR的分步演練:-) – 2009-07-21 23:45:53
我更新了演練,使用Warbler顯示戰爭創建,並在Glassfish上運行JRuby/Rails應用程序IIS。享受:-) – 2009-07-22 15:05:03