On a few projects now I’ve used jruby with rake. I know that I can use rvm and just fetch the gems per project, but for developers stuck on windows that way is a little more than difficult. So here’s how I package up rubygems in a JAR.
#!/bin/bash mkdir gemjar java -jar jruby-complete-1.6.3.jar -S gem install -i ./gemjar haml --version 3.1.2 --no-rdoc --no-ri java -jar jruby-complete-1.6.3.jar -S gem install -i ./gemjar net-scp --version 1.0.4 --no-rdoc --no-ri java -jar jruby-complete-1.6.3.jar -S gem install -i ./gemjar jruby-openssl --version 0.7.4 --no-rdoc --no-ri java -jar jruby-complete-1.6.3.jar -S gem install -i ./gemjar fpm --version 0.3.7 --no-rdoc --no-ri jar cf ruby-gems.jar -C gemjar . rm -rf gemjar
You then invoke jruby rake via:
#!/bin/bash java -jar jruby-complete-1.6.3.jar -rruby-gems.jar -S rake build.rb $@
This means that you can then invoke the following useful little nuggets:
task :list_gems do
require "rubygems/gem_runner"
Gem::GemRunner.new.run ["list"]
end
task :sass_watch do
require 'haml'
require 'haml/exec'
opts = Haml::Exec::Sass.new ['--watch', 'src/main/sass:src/main/webapp/static/css']
opts.parse!
end
task :ssh_copy, :file do |t, args|
require "net/ssh"
require "net/scp"
Net::SSH.start("repository.remote", "user") do |ssh|
ssh.scp.upload!(args.file, "/tmp/files/")
end
end
task :make_rpm => :make_war do
fail "Please install rpm-build to make RPMs!" unless system("rpmbuild --version")
require "fpm"
require "fpm/program"
exit_code = FPM::Program.new.run([
"-s", "dir", "-t", "rpm", "-n", APPLICATION_NAME, "-v", RPM_VERSION_NUMBER, "-a", "all",
"--post-install", "target/rpmbuild/opt/application/bin/post_install.sh",
"--pre-uninstall", "target/rpmbuild/opt/application/bin/pre_uninstall.sh",
"-C", "target/rpmbuild", "opt"
])
fail "Build failed" if exit_code != 0
end
How awesome is this?
#1 by Igal on 29 December 2012 - 4:42 pm
Quote
I’m trying to package a jar with JRuby and Compass/Sass so that it all goes in one jar file.
I tried to follow your instructions above but I keep getting the error: jruby: No such file or directory — gem (LoadError)
please note that I’m using JRuby1.7.1 so I don’t have a jar named jruby-complete-1.6.3.jar — I’m not even sure what the working directory should be for those commands to work? I do have jruby-1.7.1\lib\jruby.jar
I tried running different variations of C:\jruby-1.7.1\lib>java -jar jruby.jar -S gem install -i gemjar compass
but they all result in the same error.
thank you
#2 by Tom on 8 May 2013 - 1:20 pm
Quote
@Igal, not sure where you got your jruby, but you can download the jruby complete jar from the JRuby download page http://jruby.org/download