[jruby] How to integrate local GEMs, when running from a ScriptingContainer?

changepoint_advi.fischer at extaccount.com changepoint_advi.fischer at extaccount.com
Tue Jan 12 20:50:15 JST 2016


Good to know! I *do* want to deploy on an OSGi container eventually.

So, is my modification to your suggestion (for having the gems installed into a subdirectory) sound with respect to OSGi deploying, i.e. doing a

    .....generate_dir_info 'gem/gems'
repsectively
    .....generate_dir_info 'gem/specifications'

and then, for making the jar file, do a -C to temporarily switch directories, i.e.

   jar c ... -C gem .

or should I better do a

    chdir gem
    .....generate_dir_info './gems'

in order to create the directory information from the gem base directory (instead of the project directory)?


From: JRuby [mailto:jruby-bounces at ruby-lang.org] On Behalf Of christian
Sent: Tuesday, January 12, 2016 11:13 AM
To: JRuby project mailing list
Subject: Re: [jruby] How to integrate local GEMs, when running from a ScriptingContainer?

Ronald,
this generate_dir_info creates directory info file .jrubydir for each directory. some classloaders do not allow to list directories or better they do not give me jar-url to resource which JRuby can use to list the directory. so probably your application works without those extra .jrubydir files but in case to want to deploy on an OSGi container then you would need those.
just realized that it is high time to grab this conversation and make a wiki on the jruby.org<http://jruby.org> site on this topic :)
-christian

On Tue, Jan 12, 2016 at 11:00 AM, <changepoint_advi.fischer at extaccount.com<mailto:changepoint_advi.fischer at extaccount.com>> wrote:
> From: JRuby [mailto:jruby-bounces at ruby-lang.org<mailto:jruby-bounces at ruby-lang.org>] On Behalf Of christian

> jruby -S gem install GEMNAME --install-dir .
> jruby -r jruby/commands -e JRuby::Commands.generate_dir_info ./gems
> jruby -r jruby/commands -e JRuby::Commands.generate_dir_info ./specifications
>
> jar cvfm app.jar ..... gems specifications
> then use IsolatedScriptingContainer which will set GEM_HOME and GEM_PATH to uri:classloader:/ that is where the gems are found inside the jar. no need to set it manually.
> - christian

Hi Christian,

thanks for the explanation. In short - it basically works, after a few trivial modifications.

As you said, IsolatedScriptingContainer makes the use of GEM_HOME/GEM_PATH unnecessary.  One difference between my setup and yours (and which turned out was the cause of most headache) was, that you used the project directory for installing the gems (--install-dir .), while I was putting them into a subdirectory (--install-dir gem), because I didn't want the directories 'specifications', 'cache' etc. to show up into our top level project directory. However, this requires to use a trick, when putting the gem into a jar: I can't simply include 'gem', nor 'gem/gems', into the jar. Even with an IsolatedScriptingContainer, the gems would not be found. Instead, I have to use

    jar ..... -C gem gems -C gem specification

From my understanding, the -C gem flag "lifts" the gem directories one level up inside the jar file, and this seems to be necessary for the gems to be located.

I have also included the JRuby::Commands.generate_dir_info  commands, actually in a slightly different forms (you forgot the quote characters):

    jruby -r jruby/commands -e "JRuby::Commands.generate_dir_info 'gem/gems'"
    jruby -r jruby/commands -e "JRuby::Commands.generate_dir_info 'gem/specifications'"

I just wonder, why these are necessary. I googled for generate_dir_info, but didn't find anything which would explain, what this command does and why it is necessary here. Could you enlighten me in this respect?

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.


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/20160112/fbac349d/attachment-0001.html>


More information about the JRuby mailing list