Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.jruby.exceptions.RaiseException: (NameError) uninitialized constant #4987

Closed
ralleman opened this issue Jan 17, 2018 · 6 comments
Closed

Comments

@ralleman
Copy link

I'm repeating what I've written on Stackoverflow here https://stackoverflow.com/questions/48302471/org-jruby-exceptions-raiseexception-nameerror-uninitialized-constant/48304548#48304548. Looks like a bug to me.

I'm getting the following error from a JRuby wrapping of the ActiveMerchant library:

org.jruby.exceptions.RaiseException: (NameError) uninitialized constant ActiveMerchant::Billing::SecurePayAuGateway
    at org.jruby.RubyModule.const_missing(org/jruby/RubyModule.java:3345)
    at org.jruby.RubyModule.const_get(org/jruby/RubyModule.java:3290)
    at RUBY.createGateway(classpath:/scripts/main.rb:79)

The code initiating it is:

gateway = ActiveMerchant::Billing::const_get(name).new(options)

I think this is happening because there is some dynamic loading of the gateways happening in gateways.rb:

module ActiveMerchant
    module Billing
        load_path = Pathname.new(__FILE__ + '/../../..')
        Dir[File.dirname(__FILE__) + '/gateways/**/*.rb'].each do |filename|
            gateway_name      = File.basename(filename, '.rb')
            gateway_classname = "#{gateway_name}_gateway".camelize
            gateway_filename  = Pathname.new(filename).relative_path_from(load_path).sub_ext('')

            autoload(gateway_classname, gateway_filename)
        end
    end
end

This works during unit tests because the Ruby files are real files in my Maven target directory. However in the final application, the Ruby files are contained within a Jar which is in a Jar.

@kares
Copy link
Member

kares commented Jan 18, 2018

please - as the guidelines suggest - you should specify the JRuby version you're using at the minimal.
old (defunct) JRuby 1.7 had autoload-ing issues that simply won't fix and are expected to be resolved on 9K

@ralleman
Copy link
Author

ralleman commented Jan 18, 2018

Sorry, version 9.1.15.0 JRuby. And I'm using ActiveMerchant gem 1.75.0. I'm using gem-maven-plugin 1.0.0 for assembly. Java 8.

@ralleman
Copy link
Author

I've managed to get the app working by externalising the gems. Unfortunately I couldn't get it working if the gems are inside any jar file, including the top level one.

@mkristian
Copy link
Member

@ralleman yes, that is probably not working due to maybe Pathname.new(filename).relative_path_from(load_path) or some of the other path manipulation you mentioned in your issue. so externalising is the thing to go.

@headius
Copy link
Member

headius commented Feb 13, 2018

@ralleman If you can investigate more, or provide a simple repro (like a git repository we can just clone and run) we might be able to do more here, but since the related Ruby libraries are using their own tricks to look up other files we might be a little stuck. You could put some logic into the Billing module code you show above and see where it's getting mixed up about paths inside the jar. Dir[], File.basename and the others should work inside jars, but there's a lot of caveats.

@kares
Copy link
Member

kares commented Dec 6, 2022

closing as defunct

@kares kares closed this as completed Dec 6, 2022
@kares kares added this to the Invalid or Duplicate milestone Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants