Nick Sieger: Self-cloning JRuby and RubyGems in a Jardo what you lovetag:blog.nicksieger.com,2005:TypoTypo2007-08-31T19:10:59+00:00Nickurn:uuid:13d91f02-d84d-4dfe-81d0-48a28f0c2ee22007-01-12T15:30:28+00:002007-08-31T19:10:59+00:00Comment on Self-cloning JRuby and RubyGems in a Jar by Nick<p>I commented on this in the JIRA issue. Basically, you need to pass <code>-Djruby.home=/custom/path</code> on the command line.</p>
<div class='typocode'><pre><code class='typocode_default '>java -Djruby.home=/custom/path -jar jruby-complete.jar ...</code></pre></div>arisbartee@gmail.comurn:uuid:62b8cd44-3770-4017-9a0c-285d1c46ce752007-01-12T14:35:48+00:002007-08-31T19:10:59+00:00Comment on Self-cloning JRuby and RubyGems in a Jar by arisbartee@gmail.com<p>I really like playing with the “complete” jar version of jruby, Thanks man.</p>
<p>How do I tell it that my “.jruby” directory is not under my user account. I’ve set the environment variable JRUBY_HOME to where I’d like to go, but no dice.</p>Nick Siegerurn:uuid:56bbb86c-adaf-4e91-b2a4-5644bffbea7a2007-01-12T04:27:07+00:002007-08-31T18:00:07+00:00Self-cloning JRuby and RubyGems in a Jar<p>As part of <a href="http://jira.codehaus.org/browse/JRUBY-419">some work I’m doing</a> to make JRuby more portable and easier to run standalone without all the <code>$JRUBY_HOME</code> launcher scripts, it’s now easier than ever to get up and running with JRuby, or to launch in your build scripts or IDE in a platform-neutral way. (Note: as of this writing, this feature is in <a href="http://snapshots.repository.codehaus.org/org/jruby/jruby-complete/0.9.3-SNAPSHOT/">0.9.3 jruby-complete snapshots older than 2007/01/11 only</a>.)</p>
<p>Here, give it a try:</p>
<h3>IRB in a jar</h3>
<div class="typocode"><pre><code class="typocode_default ">$ curl -o jruby-complete.jar http://snapshots.repository.codehaus.org/org/jruby/jruby-complete/0.9.3-SNAPSHOT/jruby-complete-0.9.3-20070112.032908-4.jar
$ java -jar jruby-complete.jar --command irb
irb(main):001:0></code></pre></div>
<h3>RubyGems in a jar</h3>
<p>RubyGems needs a place to unpack and run gems, so JRuby currently will hide all that away from you in <code>~/.jruby</code>. (Also, unfortunately we exceed Java’s default memory size when downloading the RubyGems index file, so you’ll have to add the <code>-Xmx256m</code> argument for now to avoid an out of memory condition.)</p>
<div class="typocode"><pre><code class="typocode_default ">$ java -Xmx256m -jar jruby-complete.jar --command gem install tattle -y --no-rdoc --no-ri
creating /Users/nicksieger/.jruby/bin/gem
... more files extracted ...
copying /Users/nicksieger/jruby-complete.jar to /Users/nicksieger/.jruby/lib
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed tattle-1.0.1
Successfully installed hoe-1.1.7
Successfully installed rubyforge-0.4.0
Successfully installed rake-0.7.1</code></pre></div>
<p>You can still have JRuby unpack to a shared directory if you like, and use the regular shell scripts for launching JRuby. In this case, JRuby is actually replicating itself into the directory you choose. Simply add the <code>bin</code> subdirectory to your <code>$PATH</code>, and continue to use JRuby just as you would a regular Ruby installation.</p>
<div class="typocode"><pre><code class="typocode_default ">$ sudo java -jar jruby-complete.jar --command extract /opt/local/jruby
Password:
creating /opt/local/jruby/bin/gem
... more files extracted ...
copying /Users/nicksieger/jruby-complete.jar to /opt/local/jruby/lib
$ PATH=/opt/local/jruby/bin:$PATH
$ which gem
/opt/local/jruby/bin/gem
$ jirb
irb(main):001:0></code></pre></div>
<h3>Tattle-tale</h3>
<p>The <code>--command</code> argument is not limited to just <code>gem</code> and <code>irb</code>. Once you’ve installed any gem that has an accompanying executable script, you can simply pass that argument as the <code>--command</code>:</p>
<div class="typocode"><pre><code class="typocode_default ">$ java -jar jruby-complete.jar --command tattle report
ruby_install_name, jruby
LIBRUBY, jruby
target, java
arch, java
host_vendor, Apple Computer, Inc.
key, b1bd5eaf4254d9874ca297995b906be6f4975d395dd0136432f859c62a33cc8c
host_os, Mac OS X
ruby_version, 1.8.5
build, java
target_cpu, i386
prefix, /Users/nicksieger/.jruby
report_time, Thu Jan 11 22:21:57 CST 2007
rubygems_version, 0.9.0
host_cpu, i386
LIBRUBY_SO, jruby
SHELL, /bin/sh
$ java -jar jruby-complete.jar --command tattle
Posting information to Tattle server. Thanks!</code></pre></div>
<p>And lo and behold, there’s a <code>ruby_install_name</code> of <code>java</code> at the new <a href="http://tattle.rubygarden.org">Gem Tattle homepage</a>!</p>