Anyone successfully ran JRuby 1.5.3, Rails 3, Tomcat6

Hi, I've been trying to get JRuby 1.5.3 with Rails 3 to run on the Tomcat6 server with little success. Has anyone been able to do this? If so, what issues did you have to overcome to get this to work? Also, is this a combination that you would recommend for a production site, or is it all too new and untested? The latest issue I'm stuck on right now is with the mysql-connector- java-5.0.4 which comes with jruby 1.5.3 which keeps returning JDBCError: Generated keys not requested. Any feedback on this would be appreciated. Thanks.

can you run $ jruby -S rails server ? how does your Gemfile look like ? how do you setup your war files ? with warbler ?

regards, Kristian

I setup the war file with warbler. Here's the Gemfile:

source 'http://rubygems.org' gem 'rails', '3.0.1'

# Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git'

#gem 'sqlite3-ruby', :require => 'sqlite3' gem "activerecord-jdbcmysql-adapter", '1.0.2', :require =>'arjdbc' if defined?(JRUBY_VERSION)

# Use unicorn as the web server # gem 'unicorn'

# Deploy with Capistrano # gem 'capistrano'

# To use debugger # gem 'ruby-debug'

# Bundle the extra gems: # gem 'bj' # gem 'nokogiri' # gem 'sqlite3-ruby', :require => 'sqlite3' # gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to # put test-only gems in this group so their generators # and rake tasks are available in development mode: # group :development, :test do # gem 'webrat' # end

In the config/warbler.rb file I also have the following line uncommented:

config.gems += ["activerecord-jdbcmysql-adapter", "jruby-openssl"]

Also, the "jruby -S rails server" command brings up the WEBrick server not Tomcat. I propose to run Tomcat in the production environment.

my typical Gemfile starts like this and works without a problem with jetty and your error does not look tomcat-related. I would not use config.gems just add the gems you need in Gemfile.

# -*- mode: ruby -*- source 'http://rubygems.org'

gem 'rails', '3.0.0'

# Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2', :require => 'sqlite3' unless defined?(JRUBY_VERSION) gem "activerecord-jdbc-adapter" if defined?(JRUBY_VERSION) gem "jdbc-mysql", :require => false if defined?(JRUBY_VERSION)

in my Gemfile.lock I see     activerecord-jdbc-adapter (0.9.4-java)

maybe that setup helps. regards, Kristian

Thanks for your help so far Kristan. I've put the entries that you suggested into my Gemfile and redeployed to Tomcat but I still get the following error back. SEVERE: Application Error org.jruby.rack.RackInitializationException: ActiveRecord::JDBCError: Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement().: SET SQL_AUTO_IS_NULL=0

When I deploy this under the WEBrick server it runs fine (although I not creating a war file for the WEBrick server). Is there anyway to ensure that the deployed war file is using the same stack as my development environment? Thanks.

first I have to mention warble produces a production environment, so maybe you need to somehting like $ jruby -S rake :db:setup

then you can use the ruby-maven gem $ jruby -S gem install ruby-maven --pre which comes with jetty setup which you can just start with $ jetty-run and this runs in development mode or for production $ jetty-run -e production and of course to compare you should also see that webrick works in production mode $ jruby rails s -e production and then with the ruby-maven gem you can produces another warfile which might be slightly different from what warble produces (target/ XZY.war): $ rmvn package

with this we should be able to see whether this is tomcat or the servlet stack as such (since we can compare it jetty). is that all the stacktrace you get, can you increase logging on production - maybe there is more to see.

let's see if this helps to narrow down the issue

regards, Kristian

I'll go ahead and complete the process that you've outlined and see if I can narrow it down. In the meantime here's the complete trace of the error.

Nov 1, 2010 7:10:45 PM org.apache.catalina.core.ApplicationContext log SEVERE: Application Error org.jruby.rack.RackInitializationException: ActiveRecord::JDBCError: Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement().: SET SQL_AUTO_IS_NULL=0   from /Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord- jdbc-adapter-1.0.2-java/lib/arjdbc/jdbc/adapter.rb:178:in `execute'   from /Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord- jdbc-adapter-1.0.2-java/lib/arjdbc/mysql/adapter.rb:14:in `configure_connection'   from /Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord- jdbc-adapter-1.0.2-java/lib/arjdbc/mysql/adapter.rb:385:in `initialize'   from /Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord- jdbc-adapter-1.0.2-java/lib/arjdbc/jdbc/connection_methods.rb:6:in `new'   from /Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord- jdbc-adapter-1.0.2-java/lib/arjdbc/jdbc/connection_methods.rb:6:in `jdbc_connection'   from /Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord- jdbc-adapter-1.0.2-java/lib/arjdbc/mysql/connection_methods.rb:18:in `mysql_connection'   from /Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ activerecord-3.0.1/lib/active_record/connection_adapters/abstract/ connection_pool.rb:230:in `new_connection'   from /Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ activerecord-3.0.1/lib/active_record/connection_adapters/abstract/ connection_pool.rb:238:in `checkout_new_connection'    ... 50 levels...   from file:/Library/Tomcat/apache-tomcat-6.0.29/webapps/RSM/WEB-INF/ lib/jruby-rack-1.0.3.jar!/vendor/rack-1.2.1/rack/builder.rb:46:in `initialize'   from <script>:2:in `new'   from <script>:2

  at org.jruby.rack.DefaultRackApplicationFactory $4.init(DefaultRackApplicationFactory.java:184)   at org.jruby.rack.DefaultRackApplicationFactory.getApplication(DefaultRackApplicationFactory.java: 59)   at org.jruby.rack.PoolingRackApplicationFactory.getApplication(PoolingRackApplicationFactory.java: 94)   at org.jruby.rack.servlet.DefaultServletDispatcher.process(DefaultServletDispatcher.java: 36)   at org.jruby.rack.RackFilter.doFilter(RackFilter.java:59)   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: 127)   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: 298)   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java: 857)   at org.apache.coyote.http11.Http11Protocol $Http11ConnectionHandler.process(Http11Protocol.java:588)   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java: 489)   at java.lang.Thread.run(Thread.java:680) Caused by: org.jruby.exceptions.RaiseException: ActiveRecord::JDBCError: Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement().: SET SQL_AUTO_IS_NULL=0   at Kernel.raise(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ activerecord-3.0.1/lib/active_record/connection_adapters/ abstract_adapter.rb:202)   at ActiveRecord::ConnectionAdapters::AbstractAdapter.log(/Library/ Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord-jdbc- adapter-1.0.2-java/lib/arjdbc/jdbc/adapter.rb:178)   at ActiveRecord::ConnectionAdapters::JdbcAdapter.execute(/Library/ Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord-jdbc- adapter-1.0.2-java/lib/arjdbc/mysql/adapter.rb:14)   at ArJdbc::MySQL.configure_connection(/Library/Tomcat/Home/webapps/ RSM/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.0.2-java/lib/arjdbc/ mysql/adapter.rb:385)   at ActiveRecord::ConnectionAdapters::MysqlAdapter.initialize(/Library/ Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord-jdbc- adapter-1.0.2-java/lib/arjdbc/jdbc/connection_methods.rb:6)   at (unknown).new(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ activerecord-jdbc-adapter-1.0.2-java/lib/arjdbc/jdbc/ connection_methods.rb:6)   at #<Class:01x1aff2be8>.jdbc_connection(/Library/Tomcat/Home/webapps/ RSM/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.0.2-java/lib/arjdbc/ mysql/connection_methods.rb:18)   at #<Class:01x1aff2be8>.mysql_connection(/Library/Tomcat/Home/webapps/ RSM/WEB-INF/gems/gems/activerecord-3.0.1/lib/active_record/ connection_adapters/abstract/connection_pool.rb:230)   at ActiveRecord::ConnectionAdapters::ConnectionPool.new_connection(/ Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord-3.0.1/ lib/active_record/connection_adapters/abstract/connection_pool.rb:238)   at ActiveRecord::ConnectionAdapters::ConnectionPool.checkout_new_connection(/ Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord-3.0.1/ lib/active_record/connection_adapters/abstract/connection_pool.rb:194)   at ActiveRecord::ConnectionAdapters::ConnectionPool.checkout(/Library/ Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord-3.0.1/lib/ active_record/connection_adapters/abstract/connection_pool.rb:190)   at Kernel.loop(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ activerecord-3.0.1/lib/active_record/connection_adapters/abstract/ connection_pool.rb:190)   at ActiveRecord::ConnectionAdapters::ConnectionPool.checkout(file:/ Library/Tomcat/apache-tomcat-6.0.29/webapps/RSM/WEB-INF/lib/jruby- stdlib-1.5.3.jar!/META-INF/jruby.home/lib/ruby/1.8/monitor.rb:191)   at MonitorMixin.mon_synchronize(/Library/Tomcat/Home/webapps/RSM/WEB- INF/gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/ abstract/connection_pool.rb:189)   at ActiveRecord::ConnectionAdapters::ConnectionPool.checkout(/Library/ Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord-3.0.1/lib/ active_record/connection_adapters/abstract/connection_pool.rb:96)   at ActiveRecord::ConnectionAdapters::ConnectionPool.connection(/ Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord-3.0.1/ lib/active_record/connection_adapters/abstract/connection_pool.rb:318)   at ActiveRecord::ConnectionAdapters::ConnectionHandler.retrieve_connection(/ Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activerecord-3.0.1/ lib/active_record/connection_adapters/abstract/ connection_specification.rb:97)   at #<Class:01x1aff2be8>.retrieve_connection(/Library/Tomcat/Home/ webapps/RSM/WEB-INF/gems/gems/activerecord-3.0.1/lib/active_record/ connection_adapters/abstract/connection_specification.rb:89)   at #<Class:01x1aff2be8>.connection(/Library/Tomcat/Home/webapps/RSM/ WEB-INF/gems/gems/arel-1.0.1/lib/arel/engines/sql/engine.rb:9)   at Arel::Sql::Engine.connection(/Library/Tomcat/Home/webapps/RSM/WEB- INF/gems/gems/arel-1.0.1/lib/arel/engines/sql/relations/table.rb:37)   at Arel::Table.initialize(/Library/Tomcat/Home/webapps/RSM/WEB-INF/ gems/gems/activerecord-3.0.1/lib/active_record/base.rb:850)   at (unknown).new(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ activerecord-3.0.1/lib/active_record/base.rb:850)   at #<Class:01x1aff2be8>.arel_table(/Library/Tomcat/Home/webapps/RSM/ WEB-INF/gems/gems/activerecord-3.0.1/lib/active_record/base.rb:896)   at #<Class:01x1aff2be8>.relation(/Library/Tomcat/Home/webapps/RSM/WEB- INF/gems/gems/activerecord-3.0.1/lib/active_record/named_scope.rb:32)   at ActiveRecord::NamedScope::ClassMethods.scoped(/Library/Tomcat/Home/ webapps/RSM/WEB-INF/gems/gems/activerecord-3.0.1/lib/active_record/ base.rb:441)   at #<Class:01x1aff2be8>.limit(/Library/Tomcat/apache-tomcat-6.0.29/ webapps/RSM/WEB-INF/app/models/artist.rb:5)   at (unknown).(unknown)(/Library/Tomcat/apache-tomcat-6.0.29/webapps/ RSM/WEB-INF/app/models/artist.rb:239)   at (unknown).(unknown)(/Library/Tomcat/apache-tomcat-6.0.29/webapps/ RSM/WEB-INF/app/models/artist.rb:239)   at Kernel.require(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ activesupport-3.0.1/lib/active_support/dependencies.rb:239)   at ActiveSupport::Dependencies::Loadable.require(/Library/Tomcat/Home/ webapps/RSM/WEB-INF/gems/gems/activesupport-3.0.1/lib/active_support/ dependencies.rb:227)   at ActiveSupport::Dependencies::Loadable.load_dependency(/Library/ Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activesupport-3.0.1/lib/ active_support/dependencies.rb:239)   at ActiveSupport::Dependencies::Loadable.require(/Library/Tomcat/Home/ webapps/RSM/WEB-INF/gems/gems/activesupport-3.0.1/lib/active_support/ dependencies.rb:346)   at ActiveSupport::Dependencies.require_or_load(/Library/Tomcat/Home/ webapps/RSM/WEB-INF/gems/gems/activesupport-3.0.1/lib/active_support/ dependencies.rb:300)   at ActiveSupport::Dependencies.depend_on(/Library/Tomcat/Home/webapps/ RSM/WEB-INF/gems/gems/activesupport-3.0.1/lib/active_support/ dependencies.rb:216)   at ActiveSupport::Dependencies::Loadable.require_dependency(/Library/ Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/railties-3.0.1/lib/rails/ engine.rb:138)   at Rails::Engine.eager_load!(/Library/Tomcat/Home/webapps/RSM/WEB-INF/ gems/gems/railties-3.0.1/lib/rails/engine.rb:137)   at Array.each(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ railties-3.0.1/lib/rails/engine.rb:137)   at Rails::Engine.eager_load!(/Library/Tomcat/Home/webapps/RSM/WEB-INF/ gems/gems/railties-3.0.1/lib/rails/engine.rb:135)   at Array.each(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ railties-3.0.1/lib/rails/engine.rb:135)   at Rails::Engine.eager_load!(/Library/Tomcat/Home/webapps/RSM/WEB-INF/ gems/gems/railties-3.0.1/lib/rails/application.rb:108)   at Rails::Application.eager_load!(/Library/Tomcat/Home/webapps/RSM/ WEB-INF/gems/gems/railties-3.0.1/lib/rails/application/finisher.rb:41)   at (unknown).(unknown)(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/ gems/railties-3.0.1/lib/rails/initializable.rb:25)   at Kernel.instance_exec(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/ gems/railties-3.0.1/lib/rails/initializable.rb:25)   at Kernel.instance_exec(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/ gems/railties-3.0.1/lib/rails/initializable.rb:25)   at Rails::Initializable::Initializer.run(/Library/Tomcat/Home/webapps/ RSM/WEB-INF/gems/gems/railties-3.0.1/lib/rails/initializable.rb:50)   at Rails::Initializable.run_initializers(/Library/Tomcat/Home/webapps/ RSM/WEB-INF/gems/gems/railties-3.0.1/lib/rails/initializable.rb:49)   at Array.each(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ railties-3.0.1/lib/rails/initializable.rb:49)   at Rails::Initializable.run_initializers(/Library/Tomcat/Home/webapps/ RSM/WEB-INF/gems/gems/railties-3.0.1/lib/rails/application.rb:134)   at Rails::Application.initialize!(/Library/Tomcat/Home/webapps/RSM/ WEB-INF/gems/gems/railties-3.0.1/lib/rails/application.rb:77)   at #<Class:01x4856d15d>.method_missing(/Library/Tomcat/apache- tomcat-6.0.29/webapps/RSM/WEB-INF/config/environment.rb:9)   at (unknown).(unknown)(/Library/Tomcat/apache-tomcat-6.0.29/webapps/ RSM/WEB-INF/config/environment.rb:239)   at Kernel.require(/Library/Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/ activesupport-3.0.1/lib/active_support/dependencies.rb:239)   at ActiveSupport::Dependencies::Loadable.require(/Library/Tomcat/Home/ webapps/RSM/WEB-INF/gems/gems/activesupport-3.0.1/lib/active_support/ dependencies.rb:225)   at ActiveSupport::Dependencies::Loadable.load_dependency(/Library/ Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activesupport-3.0.1/lib/ active_support/dependencies.rb:591)   at ActiveSupport::Dependencies.new_constants_in(/Library/Tomcat/Home/ webapps/RSM/WEB-INF/gems/gems/activesupport-3.0.1/lib/active_support/ dependencies.rb:225)   at ActiveSupport::Dependencies::Loadable.load_dependency(/Library/ Tomcat/Home/webapps/RSM/WEB-INF/gems/gems/activesupport-3.0.1/lib/ active_support/dependencies.rb:239)   at ActiveSupport::Dependencies::Loadable.require(file:/Library/Tomcat/ apache-tomcat-6.0.29/webapps/RSM/WEB-INF/lib/jruby-rack-1.0.3.jar!/ jruby/rack/rails.rb:161)   at JRuby::Rack::RailsBooter::Rails3Environment.load_environment(file:/ Library/Tomcat/apache-tomcat-6.0.29/webapps/RSM/WEB-INF/lib/jruby- rack-1.0.3.jar!/jruby/rack/rails.rb:165)   at JRuby::Rack::RailsBooter::Rails3Environment.to_app(file:/Library/ Tomcat/apache-tomcat-6.0.29/webapps/RSM/WEB-INF/lib/jruby- rack-1.0.3.jar!/jruby/rack/rails.rb:186)   at #<Class:01x49450f34>.new(<script>:2)   at (unknown).(unknown)(file:/Library/Tomcat/apache-tomcat-6.0.29/ webapps/RSM/WEB-INF/lib/jruby-rack-1.0.3.jar!/vendor/rack-1.2.1/rack/ builder.rb:46)   at Kernel.instance_eval(file:/Library/Tomcat/apache-tomcat-6.0.29/ webapps/RSM/WEB-INF/lib/jruby-rack-1.0.3.jar!/vendor/rack-1.2.1/rack/ builder.rb:46)   at Kernel.instance_eval(file:/Library/Tomcat/apache-tomcat-6.0.29/ webapps/RSM/WEB-INF/lib/jruby-rack-1.0.3.jar!/vendor/rack-1.2.1/rack/ builder.rb:46)   at Rack::Builder.initialize(<script>:2)   at (unknown).new(<script>:2)   at (unknown).(unknown)(:1)

Thanks.

from the stacktrace I see that it tries to create a new artist on startup. is this done somehow in an initializer or some so ?

the actual error says that the autoincremented ids are not handled correctly. since you say it works with development webrick, it is not config problem as such. but you need to make sure that webrick against the production DB works:

$ jruby -S rails server -r production

regards Kristian

PS still do not believe it is related to the servlet/tomcat as such

I ran this against the production environment under WEBrick and it works without error. At the console I see the following output. Notice that it still runs the SQL statement: SET SQL_AUTO_IS_NULL=0 But it doesn't generate the same error that it does when I run it as a war file.

$ jruby -S rails server -e production => Booting WEBrick => Rails 3.0.1 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2010-11-02 09:11:50] INFO WEBrick 1.3.1 [2010-11-02 09:11:50] INFO ruby 1.8.7 (2010-09-28) [java] [2010-11-02 09:11:50] INFO WEBrick::HTTPServer#start: pid=46200 port=3000

Started GET "/albums/list" for 0:0:0:0:0:0:0:1%0 at Tue Nov 02 09:12:06 -0700 2010   SQL (1.0ms) SET SQL_AUTO_IS_NULL=0   Processing by AlbumsController#list as HTML   Album Load (10.0ms) SELECT `albums`.* FROM `albums` ORDER BY albums.albumTitle ASC Rendered albums/list.html.erb within layouts/application (220.0ms) Completed 200 OK in 490ms (Views: 265.0ms | ActiveRecord: 11.0ms)

As for running this with jetty, I did get it installed but I'm not familiar with maven and was not able to find any detailed instructions for running it within the context of a jruby project. i.e. no idea where the pom.xml file goes or what should be in it. The mvn package command just gave me a bunch of errors.

This does seem to be specific to Tomcat. I ran the same war file under the jetty server and it ran without error. I then reran it under Tomcat and I got the

SEVERE: Application Error org.jruby.rack.RackInitializationException: ActiveRecord::JDBCError: Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement().: SET SQL_AUTO_IS_NULL=0

error again.

OK - it is somehow related with your tomcat setup.

my application works with tomcat6 as well with jetty.

I also found your previous post. which was related to mysql-connector- java-5.1.13-bin.jar

my WEB-INF/lib directory from the warfile has only jruby-complete.jar + jruby-rack.jar in it, everything else comes from the gems in WEB-INF/ gems.

next thought is that the tomcat has mysql-connector-java-5.1.13- bin.jar in shared lib for warfiles ?

with regards, Kristian

OK, based on your previous email I've finally gotten to the bottom of this. I found a mysql-connector-java-5.1.13-bin.jar file in my $CATALINA_HOME/lib directory. After removing that file the error went away. Kristian, Thank you very much for helping me solve this problem.

great. and actually it is a drawback that you can not share jdbc drivers between applications when using rails in at one application. maybe future versions of jruby will allow this.

regards Kristian