From: Rob Biedenharn Date: 2010-02-24T00:48:17+09:00 Subject: Re: Including gems in a bundle with Rawr (Jruby) On Feb 23, 2010, at 10:28 AM, Eric Christopherson wrote: > On Mon, Feb 22, 2010 at 12:28 AM, James Britt > wrote: >> Eric Christopherson wrote: >>> >>> OK. I was able to get it to load Barby, but I had to add >>> 'lib/ruby/barby/lib' to my $LOAD_PATH. I don't understand the >>> purpose >>> of unpacking the gem into lib/ruby specifically, when it could >>> reside >>> anywhere within the hierarchy. >> >> Wherever you want to place it, you have to be sure that the load path >> includes it. The rawr build_config has lib/ruby by default, I >> believe. (You >> need to indicate what local paths to set for $: in your code, but >> also what >> folders should be packaged up by rawr, and how they should be >> structured in >> any resulting jar file.) > > OK. I put this at the top of my script: > > $LOAD_PATH << 'lib/ruby/barby/lib' > $LOAD_PATH << 'lib/ruby/prawn/lib' > $LOAD_PATH << 'lib/ruby/prawn-core/lib' > $LOAD_PATH << 'lib/ruby/prawn-layout/lib' > $LOAD_PATH << 'lib/ruby/prawn-security/lib' (Disclaimer: This answer is based solely on Ruby knowledge, not JAR behavior or JRuby) Does it work if you do: $LOAD_PATH.unshift 'lib/ruby/prawn-security/lib' $LOAD_PATH.unshift 'lib/ruby/prawn-layout/lib' $LOAD_PATH.unshift 'lib/ruby/prawn-core/lib' $LOAD_PATH.unshift 'lib/ruby/prawn/lib' $LOAD_PATH.unshift 'lib/ruby/barby/lib' this puts your directories at the front -Rob > This allows the jarred script to run -- but I later realyzed that it's > still reading the files from the filesystem. If I run the jar from a > different directory, or if I move or delete the lib directory, it is > unable to load them. > > Questions: > 1. How do I add libraries *inside the jar* to my $LOAD_PATH? > 2. Is there a more elegant way to add them than to just list each one > at the top of my script? I thought the manifest.rb file was supposed > to take care of this, but it doesn't. > 3. What is actually supposed to go in manifest.rb? > >> >> Technically, you can set this up as you like, but it's far easier >> to use and >> to explain using some rawr conventions then saying, abstractly, you >> can set >> up your sub-dirs and load path almost any way you like. Because, as >> it >> happens, you have to be careful, since (as the page explains) code >> inside >> gems sometimes makes assumptions about it's parent directories and >> such. >> >> For example, I had trouble using the 'builder' code. It came down >> to there >> being 2 builder.rb files. One would load the other. But if $: is >> not set >> up correctly, then the wrong one may be found first, with annoying >> results. >> (And I'm pretty sure I wrote an earlier version of the page under >> discussion precisely because of these issues.) > > OK. > >> >>> >>>> If you have code that is attempting to load a gem instead of >>>> trying to >>>> load >>>> files out of your bundled app then something is likely wrong. >>>> >>>> (Note that the example code on that help page never makes use of >>>> rubygems. >>>> Only plain old 'require'.) >>>> >>>> Some gems contain code that makes a call to "require 'rubygems'". >>>> (There >>>> was >>>> a previous thread on ruby-talk about how inane this is.) >>> >>> Yes, and I see now that prawn (which I also need) does just that. :( >> >> GREG! on noes ... :) > > Interestingly, prawn works just fine as long as the prawn directories > are available on the file system -- even though it does a "require > 'rubygems'". (I've even uninstalled the actual prawn gems and it still > works.) > >> >>> >>>> I usually hate to tell people "don't do that" when they ask how >>>> do do >>>> something, but trying to use rubygems from inside an app packaged >>>> up with >>>> rawr is just asking for trouble. One of the purposes of rawr is >>>> create >>>> self-sufficient apps. >>> >>> That's what I want to do: make a program (that uses some gems) and >>> package them all together so they don't need to be installed >>> separately. I must be misunderstanding the intention of the page >>> we're >>> discussing; I thought it was about doing that. >> >> The page is setting up unpacked gem files in an app. (The larger >> premise of >> rawr is that the app has a main file, with all other required files >> being >> included in subdirectories or jars, all bundled up in such a way >> that Java >> can execute it. ) >> >> rawr can build installers for your app that makes sure all the >> related files >> get put in place. >> >> But you have to unbundle any gems used by your code. And at that >> point, you >> should thinking of them as gems, and simply as libs that live in a >> subdirectory of your application folder. > Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com