Lets have a Hello world program through jruby and prepare a executable jar through warbler.
Let's assume jruby already installed . In my case I used jruby 1.7.8
Please create the below directory structure :
HelloWorld---|
|--bin--main.rb
|--lib--hello--hello.rb
|--Gemfile -------File
|--helloworld.gemspec -------File
copy the below content to the respective file, then execute the below steps through terminal. at the end you should have a HelloWorld.jar in your project directory and follow the step number (5) to get the output.
helloworld.gemspec :
GemFile :
hello.rb :
main.rb :
Let's assume jruby already installed . In my case I used jruby 1.7.8
Please create the below directory structure :
HelloWorld---|
|--bin--main.rb
|--lib--hello--hello.rb
|--Gemfile -------File
|--helloworld.gemspec -------File
copy the below content to the respective file, then execute the below steps through terminal. at the end you should have a HelloWorld.jar in your project directory and follow the step number (5) to get the output.
- install bundler gem : gem install bundler
- change to the directory HelloWorld
- execute bundle : $> bundle
- warble compiled jar
- java -jar HelloWorld.jar
helloworld.gemspec :
Gem::Specification.new do |s| s.name = 'helloworld' s.version = '1.0.0' s.authors = ['Khirod Patra'] s.date = '2013-07-03' s.description = 'Hello World' s.email = ['khirodpatra@gmail.com'] s.homepage ='khirodblog.blogspot.com/'
s.require_paths = ['lib','bin'] s.files = Dir.glob("{bin,lib}/**/*") s.executables = s.files.select { |f| f =~ /^bin\// }.map{ |f| File.basename(f) } s.default_executable = 'bin/main.rb' end
GemFile :
source 'https://rubygems.org' gem 'warbler'
hello.rb :
module Hello class SayHello def hello puts "hello World" end endend
main.rb :
#!/usr/bin/env ruby require 'rubygems'
require 'java' my_lib = File.expand_path(File.dirname(__FILE__) + "/../lib")$LOAD_PATH.unshift(my_lib) unless $LOAD_PATH.include?(my_lib) require 'hello/hello' module Hello class Main SayHello.new.hello endend