Self-cloning JRuby and RubyGems in a Jar
Posted by Nick Sieger Fri, 12 Jan 2007 04:27:07 GMT
As part of some work I’m doing to make JRuby more portable and easier to run standalone without all the
$JRUBY_HOME 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 0.9.3 jruby-complete snapshots older than 2007/01/11 only.)
Here, give it a try:
IRB in a jar
$ 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>
RubyGems in a jar
RubyGems needs a place to unpack and run gems, so JRuby currently will hide all that away from you in
~/.jruby. (Also, unfortunately we exceed Java’s default memory size when downloading the RubyGems index file, so you’ll have to add the
-Xmx256m argument for now to avoid an out of memory condition.)
$ 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
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
bin subdirectory to your
$PATH, and continue to use JRuby just as you would a regular Ruby installation.
$ 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>
--command argument is not limited to just
irb. Once you’ve installed any gem that has an accompanying executable script, you can simply pass that argument as the
$ 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!
And lo and behold, there’s a
java at the new Gem Tattle homepage!