Develop a Jruby Gem

1. Bundle a new gem

1
bundle gem jruby_gem

edit jrubygem.gemspec

1
2
3
4
Gem::Specification.new do |spec|
  ...
  spec.adddependency "jbundler"
end

Add TestUnit

1) edit jruby_gem.gemspec

1
2
3
4
Gem::Specification.new do |spec|
  ...
  spec.add_development_dependency "minitest"
end

2) edit RakeFile

Add test task code as below.

1
2
3
4
5
6
7
8
9
10
...
require 'rake/testtask'

Rake::TestTask.new do |t|
  t.libs << 'test'
  t.pattern = "test/*_test.rb"
end

desc "Run tests"
task :default => :test

3) create test/test_helper.rb

1
2
3
4
5
require 'jruby_gem'

require 'minitest/autorun'
require 'minitest/unit'
require 'minitest/pride'

Add Jar Dependency

edit jruby_gem.gemspec

1
2
3
4
Gem::Specification.new do |spec|
  ...
  spec.requirements << "jar 'jar-name', 'jar-version'"
end

Add Initializer

edit jrubygem/jrubygem.rb

2. In Rails App

edit Gemfile

1
gem 'jruby_gem', path: 'xxx'

1
2
3
touch Jarfile

jbunle

jbundle will read the requirements of jruby_gem.gemspec and then configure the classpath

Reference

  1. http://blakewilliams.me/blog/developing-gems-with-tdd-and-minitest-pt-1
  2. https://github.com/mkristian/jbundler/wiki/Gem-with-declared-jars
  3. https://github.com/richfisher/jruby_activiti