Skip to content

Instantly share code, notes, and snippets.

@headius
Created January 15, 2010 23:03
Show Gist options
  • Save headius/278497 to your computer and use it in GitHub Desktop.
Save headius/278497 to your computer and use it in GitHub Desktop.
~/projects/jruby/tmp ➔ cat ruby_util.rb
require 'java'
require 'vendor/gems/environment'
require 'rake'
class MyRubyUtility
java_signature ['String'] => 'void'
def self.runRakeTask(name)
ARGV.replace([name])
Rake.application.run
end
java_signature ['String[]'] => 'void'
def self.main(args)
args.each {|arg| runRakeTask(arg)}
end
end
~/projects/jruby/tmp ➔ jrubyc --java ruby_util.rb
Compiling ruby_util.rb to class ruby_util
Generating Java class MyRubyUtility to MyRubyUtility.java
javac -cp /Users/headius/projects/jruby/lib/jruby-complete.jar:. MyRubyUtility.java
~/projects/jruby/tmp ➔ ls *.class
MyRubyUtility.class ruby_util.class
~/projects/jruby/tmp ➔ cat Gemfile
gem 'rake'
~/projects/jruby/tmp ➔ gem bundle
Calculating dependencies...
Updating source: http://gems.rubyforge.org
Caching: rake-0.8.7.gem
Installing rake (0.8.7)
Done.
~/projects/jruby/tmp ➔ cp ../lib/jruby-complete.jar rake_runner.jar
~/projects/jruby/tmp ➔ cat mymanifest
Main-Class: MyRubyUtility
~/projects/jruby/tmp ➔ jar ufm rake_runner.jar mymanifest ruby_util.class MyRubyUtility.class `find vendor -name \*.rb`
Jan 15, 2010 4:59:11 PM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Main-Class
~/projects/jruby/tmp ➔ cat Rakefile
require 'rake'
task :hello do
puts "hello world!"
end
~/projects/jruby/tmp ➔ java -jar rake_runner.jar hello
(in /Users/headius/projects/jruby/tmp)
hello world!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment