Creating a gem using Jruby and not Ruby

家住魔仙堡 提交于 2019-12-25 04:15:24

问题


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.


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/32433839/creating-a-gem-using-jruby-and-not-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!