0

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.

EDIT:

I added the following to the jruby_gem.gemspec file

s.platform = 'java'

Built the gem using the command:

gem build jruby_gem.gemspec

and installed it using the command:

gem install jruby_gem-0.0.0

And when I tried to run it using the commands:

irb
require 'jrubt_gem'

I still got the same error.

3
  • Is your gem written in pure ruby or does it call java libraries? Pure ruby gems should technically be able to run on MRI or jRuby. And do you get that error during installation or running the gem? If you get it when running, how are you running it? Commented Sep 7, 2015 at 8:28
  • No errors. And I include java as well as a .jar file. I build it using gem build, and install it using gem install. Commented Sep 7, 2015 at 8:32
  • @joonty please check my edits.. Commented Sep 7, 2015 at 8:39

2 Answers 2

1

Rubygems are a package format for general ruby code which is used by all ruby implementations, including MRI (the original C-Ruby), JRuby, Rubinius, and others.

When you use platform-specific code in your gems, e.g. Java for use in JRuby or C-Extensions for use in C-based Rubies, you have ti use the gem with the appropriate Ruby.

That means, if you want to call Java code directly in your gem, you have to use it with JRuby. If you just install and require the gem on MRI, it won't work.

Sign up to request clarification or add additional context in comments.

3 Comments

so I have Jruby installed and when I use gem build and gem installed, it uses Ruby. How do I make it use Jruby gems to build and install my gem?
it depends on how you installed ruby and jruby. You probably want to use a ruby version manager like rvm, rbenv or even chruby.
appreciate your help, thanks. I hope this helps someone else as well.
0

Using the following commands

jruby -S gem build jruby_gem.gemspecs

and

jruby -S gem install jruby_gem-0.0.0-java.gem

worked for me, finally.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.