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.)
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.)
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 ...
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.
···
--
James Britt
www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff
www.neurogami.com - Smart application development