1

I have to create a JRuby jar file for my project. Below I provided details about my directory structure and files.

  1. Top level directory - Project1
  2. Under Project1 – I have bin, lib, src folders
  3. Under Project1/bin – I have wrapper shell script from where I am calling jruby jar.
  4. Under Project1/lib – I have jruby-complete-1.6.7.2.jar and ojdbc6.jar
  5. Under Project1/src – I have lib and tool folders
    • Under Project1/src/lib – I have main.rb file and utilfolder
    • Under Project1/src/lib/util - I have 2-ruby scripts which are getting called in main.rb.
  6. Under Project1/src/tool- I have Tool.java from where I call main.rb.

Now I have couple of questions -

  1. Do I need to bundle all the gems which I used in my ruby scripts (for example: colorize, socket, net/ssh, etc)?

  2. How do I create a JRuby jar? I saw the following posts on stackoverflow before posting my question but I got confused and kind of not able to figure out from where to start. Please provide some guidance on this.

Community
  • 1
  • 1
itsh
  • 1,063
  • 3
  • 14
  • 28
  • @joelparkerhenderson-Thanks for the answer. That was helpful but I did not need to use warbler in my project. Instead I found it easier to package all the gems into a reusable jar file by following http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar/. But right now I am facing `Exception in thread "main" java.lang.NoClassDefFoundError` error while trying to call the jar from the shell script. Can you help me fixing this? – itsh Jan 05 '15 at 20:14
  • Usually I answer my questions after finding the solution so that it can be helpful for others like me but I was trying to get the working piece before doing that. Right now I passed next step and trying to fix the other errors. I will post my question if I cannot find the solution in some time. Thanks again for the help. – itsh Jan 05 '15 at 21:35

1 Answers1

0

Below are the steps which worked for me to bundle all the gems into jruby-complete.jar.

  1. Download the jruby-complete-latest_version.jar from http://jruby.org/download.

  2. Verify which gems are included in the downloaded jar, say java -jar jruby-complete-latest_version.jar -S gem list.

  3. To push the gems into jruby-complete-latest_version.jar you need to check for all the required runtime dependecies for that gem. Example: for net-scp you need to download net-ssh gem before.

  4. Download the gems under the same directory where you have jruby-complete-latest_version.jar by using the following command:

    java -jar jruby-complete-latest_version.jar -S gem install -i ./net-ssh net-ssh --no-rdoc --no-ri java -jar jruby-completelatest_version.jar -S gem install -i ./net-scp net-scp --no-rdoc --no-ri

  5. Now add the gems inside ruby-complete-latest_version.jar by using update file (uf) option for the jar file. Example: jar uf jruby-complete-latest_version.jar -C net-ssh . jar uf jruby-complete-latest_version.jar -C net-scp .

  6. Check the gem list for the jar file to make sure all the gems are added successfully java -jar jruby-complete-latest_version.jar -S gem list

  7. Last check to make sure gems are loading successfully, run require statements on irb.

    java -jar jruby-complete-latest_version.jar -S irb irb(main):001:0> require 'rubygems' => true irb(main):002:0> require 'net/scp' => true

After I have the jruby-complete_latest_version.jar file under lib I used ANT to build the jar for my project.

Again this solution will work for the smaller projects. For big projects Warbler will the best choice as suggested by @joelparkerhenderson.

itsh
  • 1,063
  • 3
  • 14
  • 28