成功用JRuby创建war包,部署到Tomcat时加载rails报错

参考web页面:
http://edgibbs.com/2007/05/25/deploying-rails-to-tomcat-as-a-war-with-jruby/
http://www.infoq.com/cn/news/2007/08/deploying_rails_on_tomcat?
开发环境:Netbeans6.0 Beta 2,MySQL5.0,Tomcat6.0.13

1、设置好JRUBY_HOME和Path路径,将Mysql_connector.jar放到%JRUBY_HOME%\lib下和%Tomcat_HOME%\lib下(tomcat5系列是%Tomcat_HOME%\common\lib)
2、命令行:jruby gem install activerecord-jdbc --no-rdoc --no-ri,将看到类似文字

Installing ri documentation for ActiveRecord-JDBC-0.3.1...
Installing RDoc documentation for ActiveRecord-JDBC-0.3.1...
Successfully installed ActiveRecord-JDBC-0.3.1gem install ActiveRecord-JDBC

3、新建项目WarApp,并选上"Access Database using jdbc"和"Add rake targets to support APP Server Deployment(.war)"
(1)config\enviorment.rb文件里面加了下列代码,
if RUBY_PLATFORM =~ /java/
  require 'rubygems'
  gem 'ActiveRecord-JDBC'
  require 'jdbc_adapter'
 
end
(2)vendor\plugins目录下多了goldspike插件
4、新建数据库warapp,设置database.yml
development:
  adapter: jdbc

  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/warapp<your_production_database></your_production_database>
  username: root<user_name></user_name>
  password: zyb
5、生成模型Book和数据表books,生成scafford
(1)generate model Book
(2)修改 db\001_create_books.rb


def self.up<hostname></hostname>
我将WarApp.war放到%Tomcat_HOME%\webapps\下,运行Tomcat (startup.bat),http://localhost:8080/WarApp 可以看到
ruby on rails 的默认欢迎页面,但输入http://localhost:8080/WarApp/books/list 时报错了,加载rails错误。错误信息如下,
望高手补充。
javax.servlet.ServletException: Could not load Rails. See the logs for more details.
	org.jruby.webapp.RailsFactory.makeObject(RailsFactory.java:131)
	org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840)
	org.jruby.webapp.AbstractRailsServlet.serviceRequest(AbstractRailsServlet.java:144)
	org.jruby.webapp.AbstractRailsServlet.service(AbstractRailsServlet.java:131)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.jruby.webapp.FileServlet.doGet(FileServlet.java:102)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  •     create_table :books do |table|
  •       table. column :title, : string
  •       table. column :author, : string
  •     end
  •   end
    (3)在项目名WarApp右键“migrate database=>to current version”
    (4)generate scafford Book
    运行项目, http://localhost:3000/books/ 将看到我们熟悉的页面
    6、在项目名上右键“run rake task=>war:standalone:create”相当于命令“rake war:standalone:create”生成.war(使用rake war:standalone:create会增加所有需要的gems,而使用rake war:shared:create会需要调用不会加载rails相关的gems),控制台输出下来描述表示成功,第一次可能需要好几分钟,以后就快了。中间也可能失败,多试几次。
    Assembling web application
    Adding Java library commons-pool-1.3
    Adding Java library activation-1.1
    Adding Java library jruby-complete-0.9.9
    Adding Java library bcprov-jdk14-124
    Adding Java library rails-integration-1.1.1
    Adding web application
    Adding Ruby gem rails version 1.2.3
    Adding Ruby gem rake version 0.7.3
    Adding Ruby gem activesupport version 1.4.2
    Adding Ruby gem activerecord version 1.15.3
    Adding Ruby gem actionpack version 1.13.3
    Adding Ruby gem actionmailer version 1.3.3
    Adding Ruby gem actionwebservice version 1.2.3
    Adding Ruby gem ActiveRecord-JDBC version 0.3.1
    Creating web archive
    到此项目下产生了war文件WarApp.war

    将war放到%TOMCAT_HOME%\webapps下,运行Tomcat
    http://localhost:8080/WarApp/ 可以看到ruby on rails的欢迎页面,不过http://localhost:8080/WarApp/books/list 时报错,加载不到rails。错误信息如下,望:
    javax.servlet.ServletException: Could not load Rails. See the logs for more details.
     org.jruby.webapp.RailsFactory.makeObject(RailsFactory.java:131)
     org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840)
     org.jruby.webapp.AbstractRailsServlet.serviceRequest(AbstractRailsServlet.java:144)
     org.jruby.webapp.AbstractRailsServlet.service(AbstractRailsServlet.java:131)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
     org.jruby.webapp.FileServlet.doGet(FileServlet.java:102)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

  • 你可能感兴趣的:(java,tomcat,Ruby,Rails,jruby)