ActiveRecord不缺少常量Base!错误部署rails 3.2.9 jruby 1.7.2到weblogic 10.3

时间:2013-02-01 18:32:03

标签: ruby-on-rails jruby rails-activerecord meta-search

在将Rails 3.2项目部署到Weblogic 10.3时遇到此问题,并且正在寻找一个简单的答案。

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)

环境如下: JRuby 1.7.2,JRockit 1.6,Rails 3.2.9,Warbler

我部署了基本的2模型加设计用户项目,当我在浏览器中浏览它时会发生此错误。谁看过这个吗?这是我第一次使用JRuby。

编辑:

添加我最近的失败尝试。请注意,我已经尝试过jruby,jruby-jar,分别为1.6.8,1.7.0,1.7.2并没有成功。这是我的Gem文件和Warbler配置:

#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

和Warbler Config(使用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

2 个答案:

答案 0 :(得分:1)

这似乎是一个jRuby错误:http://jira.codehaus.org/browse/JRUBY-6705

答案 1 :(得分:0)

我最近与一位同事进行了一次对话,在将Jenkins部署到Weblogic时遇到了类似的问题。如果您决定将JRuby部署到Weblogic,则必须详细说明您必须执行的操作。在我的情况下,我转移到JBoss并建议你也这样做。如果必须部署到weblogic,此链接描述了确保Weblogic预加载所有必需库的必要要求。

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

如果您唯一的选择是weblogic,那么我强烈建议在开发项目之前校对一个简单的配置测试,并假设它可以正常工作。

这是一个片段:

Weblogic 12+。将其添加到项目中的文件: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> 

在以前的版本中,有一些更重要的hackage来让weblogic正确解密你的jar和依赖。特别是对于这个问题,因为我在10.3.X低于.4运行,这是步骤。

较早的Weblogic服务器

要纠正Weblogic的类加载器问题,我们需要构建一个EAR文件并将weblogic-application.xml指令放入其中。 1.使用以下结构创建一个故事内容的目录(使用你的战争而不是詹金斯):     ROOT_FOLDER /

    META-INF/
        application.xml
        weblogic-application.xml
    jenkins.war
  1. 将jenkins.war放入ROOT_Folder

  2. 创建META-INF目录

  3. 在META_INF目录(weblogic-application.xml)中创建以下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“&gt;

    webapp.encoding.default UTF-8

    org.apache javax.xml.stream。

  4. Weblogic需要这个,因为(与JBoss,Tomcat,Jetty等人不同)Weblogic在Weblogic安装JAR之前不会在WAR中加载JAR,并且通常产生的错误是在范围内存在旧版本的Ant 1.7而不是Jenkins想要的Ant 1.8.x.对于列出的javax.xml包,stax-api-1.0.1.jar也存在冲突。

    这是一个可以使用的简单application.xml

    <?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>
    

    重新压缩文件,制作新的EAR文件 安装,然后部署

    注意:如果您必须对此进行测试,请在此处评论是否有效。在我确认之前,我不会接受答案;因为我已经转移到JBoss进行干净部署。