ActiveRecord is not missing constant Base! error deploying rails 3.2.9 jruby 1.7.2 to weblogic 10.3
Asked Answered
T

2

6

Running into this issue while deploying Rails 3.2 project to Weblogic 10.3 and was looking for an easy answer.

org.jruby.exceptions.RaiseException: (NameError) ActiveRecord is not missing constant Base!
at RUBY.load_missing_constant(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:494)
at RUBY.const_missing(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:192)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613)
at RUBY.const_missing(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/meta_search-1.1.3/lib/meta_search.rb:55)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at ActiveSupport::Dependencies::Loadable.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251)
at ActiveSupport::Dependencies::Loadable.load_dependency(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236)
at ActiveSupport::Dependencies::Loadable.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activeadmin-0.5.0/lib/active_admin.rb:1)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at ActiveSupport::Dependencies::Loadable.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251)
at ActiveSupport::Dependencies::Loadable.load_dependency(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236)
at ActiveSupport::Dependencies::Loadable.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activeadmin-0.5.0/lib/active_admin.rb:1)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activeadmin-0.5.0/lib/activeadmin.rb:1)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activeadmin-0.5.0/lib/activeadmin.rb:1)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler/runtime.rb:1)
at RUBY.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler/runtime.rb:68)
at RUBY.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler/runtime.rb:66)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at RUBY.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler/runtime.rb:55)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at RUBY.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler.rb:128)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/config/application.rb:13)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/config/environment.rb:1)

Environment looks like this: JRuby 1.7.2, JRockit 1.6, Rails 3.2.9, Warbler

I deploy the basic 2 model plus devise user project and this error occurs when I browse to it in a browser. Has anyone seen this before? This is my first stint with JRuby.

Editing:

Adding my latest failed attempt. note, I've tried jruby, jruby-jars for 1.6.8, 1.7.0, 1.7.2 and have had no success. here is my Gem File and Warbler configuration:

#source 'https://rubygems.org'
source "http://bundler-api.herokuapp.com"

gem 'rails', '<3.3'

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


gem 'savon'

#gem 'jruby-openssl'
gem 'json'
#gem 'ffi', '~>1.0.9'
#gem 'sqlite3'
gem 'rake', "=10.0.2"
gem 'activerecord-oracle_enhanced-adapter', "~> 1.4.0"

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '<3.3'
  gem 'coffee-rails', '<3.3'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  #gem 'therubyrhino'
  #gem 'therubyracer'
  #gem 'libv8'

  gem 'uglifier', '>= 1.0.3'
end

platforms :jruby do
  group :assets do
    gem 'therubyrhino'
  end

  group :development, :test do
    gem 'ruby-debug'
    gem 'activerecord-jdbcsqlite3-adapter', "~> 1.2.5"
    gem 'warbler'
  end


  gem 'jruby-jars', "1.7.0"
  gem 'jruby-openssl', :require => false
end

platforms :ruby do
  group :assets do
    gem 'therubyracer'
    gem 'libv8'
  end

  group :development, :test do
    gem 'debugger'
    gem 'sqlite3'
  end

  gem 'ruby-oci8', '~> 2.1.0' # requires oracle client
end

gem 'jquery-rails'
gem 'devise'
gem 'activeadmin'
gem 'rb-readline'
gem 'validates_timeliness', '~> 3.0'
gem 'wash_out'#, :path => "~/Desktop/code/wash_out"

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn':path 

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'uby-debug'

group :development do

end

group :test do
  gem 'cucumber-rails', :require => false
  #gem 'cucumber', :require => false
  gem 'shoulda-matchers'
  gem 'json_spec'
  gem 'vcr'
  gem 'fakeweb'
  gem 'database_cleaner'
  gem 'launchy'
  gem 'webrat'
  gem 'json_spec'
  #gem 'capybara'
  #gem 'mocha'
end

group :development, :test do
  #gem 'activerecord-sqlite3-adapter', :platform => :ruby
  #gem 'activerecord-jdbc-sqlite3-adapter', :platform => :jruby
  gem 'rspec-rails'
  gem 'factory_girl_rails', "~> 4.0"
end

And Warbler Config (Using Warble War):

    class Warbler::Jar
  def replace_compiled_ruby_files(config, compiled_ruby_files)
    config.excludes += compiled_ruby_files
    compiled_ruby_files.each do |ruby_source|
      files[apply_pathmaps(config, ruby_source, :application)] = StringIO.new("load __FILE__.sub(/\.rb$/, '.class')")
    end
  end
end

Warbler::Config.new do |config|
  config.dirs = %w(app config lib log vendor tmp)
  config.webxml.jruby.compat.version = "1.9"
end
Telson answered 1/2, 2013 at 18:32 Comment(0)
D
1

This seems to be a jRuby bug: http://jira.codehaus.org/browse/JRUBY-6705

Duran answered 7/2, 2013 at 14:54 Comment(6)
Can you suggest a workaround? This issue states fixed in 1.7.0 back in June. I've tried 1.7.2, 1.7.1, 1.7.0, 1.6.8 and it doesn't seem to be fixed. The bug related seems to be accurate and my description precisely, but without much experience in jRuby, I can't do diagnostics to even report a jRuby bug.Telson
Can you update your bundle? Rails' default Gemfile sucks a little bit, change gem 'rails', '~> 3.2.x' to gem 'rails', '< 3.3' so you get the bugfix releases. Same for sass-rails and coffee-rails. ActiveSupport 3.2.9 is somewhat outdated, current version is 3.2.11.Duran
No go on the bundle update. I've tried 1.6.8 -> 1.7.2 and everything in between.Is there any specific information or guidance on narrowing in on the specific error as this whole error message is very vague.Telson
Sure. I'll modify the above with the Gemfile.Telson
The only red flag in the Gemfile I see is pinning the rake version to 10.0.2 -- you can probably do away with that unless there's a specific reason you put it in. I don't have all the moving pieces to recreate this error, but I'm curious -- what happens when you deploy to unicorn, puma, webrick or any other non-weblogic rack host? What happens when you launch the console with rails c?Autoradiograph
What if you define gem 'active_support', '>= 3.2.11' specifically in your Gemfile? Maybe this forces bundle to use a newer version.Duran
T
0

I've had a conversation recently with a colleague that also ran into a similar issue whilst deploying Jenkins to Weblogic. There is a detailed writeup of what you MUST do if you decide to deploy JRuby to Weblogic. In my case, I moved to JBoss and suggest you do the same. If you have to deploy to weblogic, this link describes the necessary requirements for ensuring that Weblogic pre-loads all of the necessary libraries.

https://wiki.jenkins-ci.org/display/JENKINS/Weblogic

If your only option is weblogic, then I'd highly recommend proofing a simple configuration test prior to developing your project with an assumption that it will work.

Here's a snippet:

Weblogic 12+. Adding this to a file in your project called: weblogic.xml

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wls="http://www.bea.com/ns/weblogic/90" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
    <wls:weblogic-version>12.1.1</wls:weblogic-version>
    <wls:context-root>jenkins</wls:context-root>
    <wls:container-descriptor>
         <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
    </wls:container-descriptor>
</wls:weblogic-web-app> 

And in previous versions there's some more important hackage to get weblogic to properly decipher your jars and dependencies. Specifically for this question, since I'm running on 10.3.X Lower than .4, here are the steps.

Older Weblogic servers

To correct Weblogic's class loader problems, we need to build an EAR file and put the weblogic-application.xml directives into it. 1. Create a directory to story the ear contents, with the following structure (use your war instead of Jenkins): ROOT_Folder/

    META-INF/
        application.xml
        weblogic-application.xml
    jenkins.war
  1. drop the jenkins.war into the ROOT_Folder

  2. create the META-INF dir

  3. create the following XML files in that META_INF dir (weblogic-application.xml):

    http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://www.bea.com/ns/weblogic/weblogic-application http://www.bea.com/ns/weblogic/weblogic-application/1.0/weblogic-application.xsd">

    webapp.encoding.default UTF-8

    org.apache. javax.xml.stream.

Weblogic needs this because (unlike JBoss, Tomcat, Jetty et. al) Weblogic will not load the JARs in the WAR before the Weblogic installed JARs, and usually the resulting error is that there is an old version of Ant 1.7 in scope, instead of Ant 1.8.x as Jenkins wants. There is also a conflict with stax-api-1.0.1.jar for the javax.xml package listed.

Here is a simple application.xml that will work

<?xml version="1.0" encoding="UTF-8"?>

<application xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
version="5">

<module id="jenkins">
<web>
<web-uri>jenkins.war</web-uri>
<context-root>/jenkins</context-root>
</web>
</module>
</application>

Rezip your files, making your new EAR file Install, then deploy

Note: If you must test this, then please comment here on whether this works. I will not be accepting an answer until I have validation; since I've moved to JBoss for the clean deploy.

Telson answered 21/2, 2013 at 15:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.