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

christian m.kristian at web.de
Tue Jan 12 01:36:29 JST 2016

this should actually work. which jruby version are you using ?

On Mon, Jan 11, 2016 at 3:11 PM, <changepoint_advi.fischer at extaccount.com>

> 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
> container.runScriptlet(org.jruby.embed.PathType.CLASSPATH,"rdir/scriptlet.rb");
> 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.
> Ronald
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ruby-lang.org/pipermail/jruby/attachments/20160111/4c2aae32/attachment.html>

More information about the JRuby mailing list