[jruby] require vs. require_relative, used from within a scriptlet

changepoint_advi.fischer at extaccount.com changepoint_advi.fischer at extaccount.com
Mon Jan 11 23:11:35 JST 2016

I'm running my JRuby application via a ScriptingContainer. Everything is in a Jar File, and the Ruby source files are all within the same subdirectory in the jar. Seen from the jar file as the base directory, by ruby files would be rdir/scriptlet.rb and rdir/application.rb. The scriptlet is called by


Within scriptlet.rb, I would like to require application.rb. I can do this in the following way:

    require 'rdir/application' # This works

I can NOT do this in the following way:

    require_relative 'application" # This does not work

I had expected, that both would work. require_relative looks up the included file relative to the directory of the including file, which is in both cases 'rdir'. Why can't I use require_relative here? Does 'require_relative' only work in this way, if it is called from within a file which itself is being processed by a 'require'/'require_relative' command?

I would prefer not having 'rdir' hardcoded in my file, and therefore would like to use require_relative, if possible.


If you are not the addressee, please inform us immediately that you have received this e-mail by mistake, and delete it. We thank you for your support.

More information about the JRuby mailing list