Note that there are some explanatory texts on larger screens.

plurals
  1. POJruby Gems-in-a-jar issue
    text
    copied!<p>I am trying to write some code in ruby (using jruby) to be compiled to java bytecode with jrubyc and deployed to a remote machine where it will be run on the JVM (no ruby available there).</p> <p>Everything works fine as long as I am happy to stick with the standard jruby library. As explained on the jruby website, I simply copy the jruby-complete.jar library to the remote machine and include it in the classpath at runtime. I fire my compiled script and it works: cool!</p> <p>The problems start when I need some other libraries (typically rubygems) to run my script.<br> I am aware of cool stuff like rawr, -which I successfully tested- to put together all you need in a single package. However that is not the solution I am looking for: I will have many small scripts to run independently and I don't want each of them to grow to at least 10 MB just because I insanely include the jruby-complete.jar in each of them.</p> <p>What I would like is to compile a .jar for each of the libraries that I will need to use, put all of them in a common folder on the remote machine and include them at runtime in the classpath when I run my compiled jruby scripts on the JVM.<br> This said, I tried to follow the instructions here: <a href="http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar" rel="nofollow noreferrer">http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar</a><br> I tried exactly the example shown there, with the "chronic" gem. Going step by step:</p> <ol> <li>Install the gem locally: java -jar jruby-complete-1.1.6.jar -S gem install -i ./chronic chronic --no-rdoc --no-ri</li> <li>Package it into a jar: jar cf chronic.jar -C chronic .</li> <li><p>Write a two lines test script, saving it as testt.rb:</p> <blockquote> <p>require 'chronic'<br> Chronic.parse('tomorrow')</p> </blockquote></li> <li><p>Compile with: jrubyc testt.rb</p></li> <li>Run the resulting java class testt.class with the following (having both jruby-complete.jar and chronic.jar in the same folder as the java class): java -cp .:/jruby-complete.jar:./chronic.jar testt</li> </ol> <p>I get the following error:</p> <p>Exception in thread "main" file:/Users/ave2/NetBeansProjects/jrubywatir/lib/jruby-complete.jar!/METAINF/jruby.home/lib/ruby/site_ruby/shared/builtin/core_ext/symbol.rb:1:in `const_missing': uninitialized constant Chronic (NameError)<br> from testt.rb:2<br> ...internal jruby stack elided...<br> from Module.const_missing(testt.rb:2)<br> from (unknown).(unknown)(:1) </p> <p>I really don't understand what I am doing wrong, and I am totally stuck on this. I am a noob in Ruby, much more used to Python: don't miss a chance to convert an infidel! :-) Thanks. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload