简体   繁体   中英

Creating a gem using Jruby and not Ruby

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.

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, eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM