warblerでRailsアプリをTomcatにのせてみる
前提
- TOMCATがインストールされている(zipとか展開するだけですが)
warblerをインストール
D:\work\ruby\ActiveRecord-JDBC\test>jruby -S 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.11 1 gem installed Installing ri documentation for warbler-0.9.11... Installing RDoc documentation for warbler-0.9.11... D:\work\ruby\ActiveRecord-JDBC\test>
いきなりwarble
D:\work\ruby\ActiveRecord-JDBC\test>jruby -S warble jar cf test.war -C tmp/war . D:\work\ruby\ActiveRecord-JDBC\test>
これで、railsプロジェクト直下にプロジェクト名.warができるらしい。
TOMCATにデプロイ
- TOMCAT_HOME/webappsにtest.warをコピー
- TOMCAT_HOME/bin/startup.bat起動
- http://localhost:8080/test
- OK
- http://localhost:8080/test/people
- NG
MissingSourceFile in PeopleController#index no such file to load -- sqlite3
なんかsqlite3になってる。。
config/database.ymlのproductionの設定を変えてみる。
production: # adapter: sqlite3 # database: db/production.sqlite3 # timeout: 5000 adapter: jdbcderby username: password: hostname: localhost database: db/production
TOMCATにデプロイ(2回目)
D:\work\ruby\ACTIVE~1\test>jruby -S warble jar cf test.war -C tmp/war . D:\work\ruby\ACTIVE~1\test>
- TOMCAT_HOME/webappsにtest.warをコピー
- TOMCAT_HOME/bin/startup.bat起動
- http://localhost:8080/test
- OK
- http://localhost:8080/test/people
- NG
MissingSourceFile in PeopleController#index no such file to load -- sqlite3
なんでか変わらず。。
config/environment.rbによさげな設定があったので、
ENV['RAILS_ENV'] ||= 'production'
の行をコメントインしてみる。
# Uncomment below to force Rails into production mode when # you don't control web/app server and can't set it the proper way ENV['RAILS_ENV'] ||= 'production'
TOMCATにデプロイ(3回目)
D:\work\ruby\ActiveRecord-JDBC\test>jruby -S warble jar cf test.war -C tmp/war . D:\work\ruby\ActiveRecord-JDBC\test>
見慣れないエラーが発生。。
最近のTomcatはスタックトレースを画面にさらさないようにしたってことですかね。
TOMCAT_HOME/logs/localhost.2008-09-11.log
致命的: Exception caught org.jruby.rack.RackInitializationException: Please install the jdbcderby adapter: `gem install activerecord-jdbcderby-adapter` (no such file to load -- active_record/connection_adapters/jdbcderby_adapter) from E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:216:in `establish_connection' from E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:209:in `establish_connection' from E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/rails-2.1.1/lib/initializer.rb:341:in `initialize_database' from E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/rails-2.1.1/lib/initializer.rb:124:in `process' from E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/rails-2.1.1/lib/initializer.rb:97:in `run' from E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/config/environment.rb:13 from E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/config/environment.rb:29:in `load' from file:/E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/jruby-rack-0.9.2.jar!/jruby/rack/rails.rb:29:in `load_environment' from file:/E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/jruby-rack-0.9.2.jar!/jruby/rack/rails.rb:152:in `new' from <script>:3 from file:/E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/jruby-rack-0.9.2.jar!/rack/builder.rb:22:in `instance_eval' from file:/E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/jruby-rack-0.9.2.jar!/rack/builder.rb:22:in `initialize' from <script>:3 at org.jruby.rack.DefaultRackApplicationFactory$4.init(DefaultRackApplicationFactory.java:154) at org.jruby.rack.DefaultRackApplicationFactory.getApplication(DefaultRackApplicationFactory.java:53) at org.jruby.rack.PoolingRackApplicationFactory.getApplication(PoolingRackApplicationFactory.java:92) at org.jruby.rack.DefaultRackDispatcher.process(DefaultRackDispatcher.java:31) at org.jruby.rack.RackFilter.doFilter(RackFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) Caused by: org.jruby.exceptions.RaiseException at Kernel.raise(E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:232) at #<Class:01xdeea66>.establish_connection(E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:216) at #<Class:01xdeea66>.establish_connection(E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:209) at #<Class:01xdeea66>.establish_connection(E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/rails-2.1.1/lib/initializer.rb:341) at Rails::Initializer.initialize_database(E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/rails-2.1.1/lib/initializer.rb:124) at Rails::Initializer.process(E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/gems/gems/rails-2.1.1/lib/initializer.rb:97) at #<Class:01x119fc9e>.run(E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/config/environment.rb:13) at (unknown).(unknown)(E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/config/environment.rb:29) at Kernel.load(file:/E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/jruby-rack-0.9.2.jar!/jruby/rack/rails.rb:29) at JRuby::Rack::RailsServletHelper.load_environment(file:/E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/jruby-rack-0.9.2.jar!/jruby/rack/rails.rb:152) at #<Class:01x16c1bce>.new(<script>:3) at (unknown).(unknown)(file:/E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/jruby-rack-0.9.2.jar!/rack/builder.rb:22) at Kernel.instance_eval(file:/E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/jruby-rack-0.9.2.jar!/rack/builder.rb:22) at Kernel.instance_eval(file:/E:/apache-tomcat-6.0.18/webapps/test/WEB-INF/lib/jruby-rack-0.9.2.jar!/rack/builder.rb:22) at Rack::Builder.initialize(<script>:3) at (unknown).(unknown)(:1)
なんかgemがうまくインストールされてないみたい。
というか、warblerはrailsのgemはwarに入れてくれるけど、その他のgemは入れてくれないかららしい。
ので、とりあえずフォルダごとコピーしてみる。
E:\jruby-1.1.4\lib\ruby\gems\1.8\gems\activerecord-jdbc-adapter-0.8.2
E:\jruby-1.1.4\lib\ruby\gems\1.8\gems\activerecord-jdbcderby-adapter-0.8.2
E:\jruby-1.1.4\lib\ruby\gems\1.8\gems\jdbc-derby-10.3.2.1
を
E:\apache-tomcat-6.0.18\webapps\test\WEB-INF\gems\gems
にコピー
TOMCATにデプロイ(4回目)
TOMCAT再起動&ページ表示 → 状況変わらず。。
ああ、gemspec入れ忘れた。。
E:\jruby-1.1.4\lib\ruby\gems\1.8\specifications\activerecord-jdbc-adapter-0.8.2.gemspec
E:\jruby-1.1.4\lib\ruby\gems\1.8\specifications\activerecord-jdbcderby-adapter-0.8.2.gemspec
E:\jruby-1.1.4\lib\ruby\gems\1.8\specifications\jdbc-derby-10.3.2.1.gemspec
を
E:\apache-tomcat-6.0.18\webapps\test\WEB-INF\gems\specifications
にコピー
TOMCATにデプロイ(5回目)
TOMCAT再起動&ページ表示
ActiveRecord::StatementInvalid in PeopleController#index ActiveRecord::ActiveRecordError: Schema 'SA' does not exist: SELECT * FROM people
今度はデータベースの中身がないよっていうようなエラーらしい。
とりあえず、元の環境に戻ってproduction用のデータベースを作ってから、フォルダごとコピーすることに。
本番環境はサーバで動かすだろうから、この問題は普通起きないかも。
D:\work\ruby\ACTIVE~1\test>jruby -S rake db:migrate RAILS_ENV=production (in D:/work/ruby/ACTIVE~1/test) == 20080911043012 CreatePeople: migrating ===================================== -- create_table(:people) -> 0.1598s -> 0 rows == 20080911043012 CreatePeople: migrated (0.1656s) ============================ D:\work\ruby\ACTIVE~1\test>
migrateの対象をproductionにするやり方は、
http://d.hatena.ne.jp/shohu33/20071203/1196643163
を参考にしました。
D:\work\ruby\ActiveRecord-JDBC\test\db\production
を
E:\apache-tomcat-6.0.18\bin\db
にコピー
っていうか、TOMCAT_HOME/binにデータベース作っちゃうのってどうよ。