Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a jruby GEM #3312

Closed
i-ask-too-many-questions opened this issue Sep 7, 2015 · 16 comments
Closed

Creating a jruby GEM #3312

i-ask-too-many-questions opened this issue Sep 7, 2015 · 16 comments

Comments

@i-ask-too-many-questions

So I was successful in writing a jruby file and reading from a jar file.

I also created a seperate Ruby gem, installed it and used it successfully.

I would like to write a gem using Jruby (and not ruby). When I did try to do so and after installing the gem, it gave me the following error:

        `require': cannot load such file -- java (LoadError)

Is there a specific way to write a gem using jruby that is different from the way to write a gem usig ruby? If so, please direct me to a useful tutorial that helps me create a gem using jruby

thank you.

@mkristian
Copy link
Member

add platform = 'java' to tell rubygems it is a jruby only gem and use
jruby itself when installing and using the gem.

@i-ask-too-many-questions
Copy link
Author

Could you be more specific, please? Also, where should I add platform = 'java' exactly?

@mkristian
Copy link
Member

mkristian commented Sep 7, 2015 via email

@i-ask-too-many-questions
Copy link
Author

I see.

The commands I use to build and install the gem are as follows:

gem build gem_name.gemspec
install ./gem_name-0.0.0

How can these be any different from jruby?

@i-ask-too-many-questions
Copy link
Author

BTW I did try to only add s.platform = 'java' and it still gave me the same error after building and installing the gem (using the previous commands)

@mkristian
Copy link
Member

I never saw the install command ! installing gems usually works: gem install -l gem_name-0.0.0-java.gem (please ensure to use the gem file produced by the gem build command.

@mkristian mkristian added this to the Invalid or Duplicate milestone Sep 7, 2015
@i-ask-too-many-questions
Copy link
Author

I ran the command:
gem build gem_name.gemspecs
which resulted in the file
gem_name-0.0.0-java.gem
so I ran the command:
gem install -l gem_name-0.0.0-java.gem
and I STILL got the error:
LoadError: cannot load such file -- java

@mkristian
Copy link
Member

the error says you are not using jruby. what is gem env telling you ?

@i-ask-too-many-questions
Copy link
Author

$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.5
- RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x64-mingw32]

I see now that Ruby gems are being used and not Jruby. How do I specify that Jruby Gems are being used?

@mkristian
Copy link
Member

mkristian commented Sep 7, 2015 via email

@i-ask-too-many-questions
Copy link
Author

I mean, thanks for linking me to that page but I already have jruby installed and my question is, how do I make sure Gem is using the jruby gems and not the Ruby gems?

@i-ask-too-many-questions
Copy link
Author

since both Jruby and Ruby use the same following command:

gem build gem_name.gemspec

@mkristian
Copy link
Member

ah - I see.

better use https://github.com/sstephenson/rbenv to install jruby or RVM to
install JRuby (link on the getting started page) or maybe jruby -S gem install gem_name-0.0.0-java.gem if you installed it and set the PATH
right. or use the bin/jruby executable directly.

@i-ask-too-many-questions
Copy link
Author

Using jruby -S gem build... and jruby -S gem install... worked for me, finally. thank you. :)

@AfolabiOlaoluwa
Copy link

I have a Gem wholly written in Ruby, supporting Rails. However, I want to bring it to JRuby to be usable on my Java code, and I am curious if there are any resources to make this happen?

This is all I have done to bring Java to it that Ruby Gem.

# ...
Gem::Specification.new do |spec|
  # ...
  if RUBY_PLATFORM =~ /java/
    spec.platform    = 'java'
end

These are all the dependencies the Gem supports:

Gem::Specification.new do |s|
  s.platform     = Gem::Platform::RUBY

  s.required_ruby_version = '>= 2.5'

  s.files = Dir['CHANGELOG', 'README.md', 'MIT-LICENSE', 'CONTRIBUTORS', 'lib/**/*', 'vendor/**/*']
  s.require_path = 'lib'

  s.metadata['allowed_push_host'] = 'https://rubygems.org'

  s.has_rdoc = true if Gem::VERSION < '1.7.0'

  s.add_dependency('activesupport', '>= 4.2')
  s.add_dependency('builder', '>= 2.1.2', '< 4.0.0')
  s.add_dependency('i18n', '>= 0.6.9')
  s.add_dependency('nokogiri', '~> 1.4')

  s.add_development_dependency('mocha', '~> 1')
  s.add_development_dependency('pry')
  s.add_development_dependency('pry-byebug')
  s.add_development_dependency('rake')
  s.add_development_dependency('test-unit', '~> 3')
  s.add_development_dependency('thor')
end

However, I will be glad if there are resources you can point me to so I can learn more about bringing Ruby Gem to Java code as I feel what I have done is not enough to make it in a Java code.

1 similar comment
@AfolabiOlaoluwa
Copy link

I have a Gem wholly written in Ruby, supporting Rails. However, I want to bring it to JRuby to be usable on my Java code, and I am curious if there are any resources to make this happen?

This is all I have done to bring Java to it that Ruby Gem.

# ...
Gem::Specification.new do |spec|
  # ...
  if RUBY_PLATFORM =~ /java/
    spec.platform    = 'java'
end

These are all the dependencies the Gem supports:

Gem::Specification.new do |s|
  s.platform     = Gem::Platform::RUBY

  s.required_ruby_version = '>= 2.5'

  s.files = Dir['CHANGELOG', 'README.md', 'MIT-LICENSE', 'CONTRIBUTORS', 'lib/**/*', 'vendor/**/*']
  s.require_path = 'lib'

  s.metadata['allowed_push_host'] = 'https://rubygems.org'

  s.has_rdoc = true if Gem::VERSION < '1.7.0'

  s.add_dependency('activesupport', '>= 4.2')
  s.add_dependency('builder', '>= 2.1.2', '< 4.0.0')
  s.add_dependency('i18n', '>= 0.6.9')
  s.add_dependency('nokogiri', '~> 1.4')

  s.add_development_dependency('mocha', '~> 1')
  s.add_development_dependency('pry')
  s.add_development_dependency('pry-byebug')
  s.add_development_dependency('rake')
  s.add_development_dependency('test-unit', '~> 3')
  s.add_development_dependency('thor')
end

However, I will be glad if there are resources you can point me to so I can learn more about bringing Ruby Gem to Java code as I feel what I have done is not enough to make it in a Java code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants