Configuring Gems in Eclipse

Can a ruby gem/module be added just like a java jar file?

I have find the answer to this question. I not sure if this is the best way to do it, but it works for me. Pro developers, can you please review this answer ? So, for now let me give quick guide for this.

1 - Install Eclipse DLTK plugin for Ruby as suggested here - Preferred Ruby plugin for Eclipse?
See the answer with photo, by James.

2 - Next, lets pick a random gem such as nokogiri and download it from rubygems.org. The file name of the Gem tells you which OS its meant for. I use windows 7 64bits. So, I take version with x64-mingw32. Here is a sample list of downloads:

1.6.4.1 November 7, 2014 java (2.37 MB)
1.6.4.1 November 7, 2014 x64-mingw32 (2.86 MB)
1.6.4.1 November 7, 2014 (8.81 MB)
1.6.4.1 November 7, 2014 x86-mingw32 (3.91 MB)
1.6.4 November 5, 2014 java (2.37 MB)
Show all versions (271 total)

3 - AFAIK, eclipse cannot use the gem file as is. You need to unpack it first. Lets say you kept the gem file in c:\RubyGems\extras, and you want to unpack it there itself.

open windows cmd > cd into the above directory > gem unpack nokogiri-1.6.4.1-x64-mingw32.gem > press enter !!!

Now, your gem will be unpacked into a folder nokogiri-1.6.4.1-x64-mingw32.

4 - Locate the nokogiri.rb file inside the unpacked folder. Its in the lib folder.
Copy the full path of this folder - c:\RubyGems\extras\nokogiri-1.6.4.1-x64-mingw32\lib. We need this for eclipse.

5 - Eclipse > create new ruby project > right click project > build path > configure build path > libraries tab > add external source folder > enter the path from step 4 > Ok > ok. You can now use the gem in your project.

6 - Testing if the steps work. Use the code in your project !

require 'nokogiri'

puts "Chenqui ! It is work!!!"

If the message prints without error, then you are a success ! To see the error you get when the required modules can't be found, add something like this require 'restclient'.

How does one debug jRuby using eclipse?

Download the Eclipse Dynamic Languages Toolkit - Ruby Development Tools. Import your ruby on rails project. Check that your Gemfile references:

gem 'ruby-debug'

Then go to windows -> preferences, and do two things:

  • setting the eclipse ruby interpreter to: c:\jruby\bin\jruby.bat

JRuby eclipse

  • setting the eclipse ruby debug engine so it's not the "fast debugger" but "ruby built-in debugger"

Sample Image

Then in the run configuration, main tab, under "ruby script" the launch script is bin/rails, and in the arguments tab server --debugger. The interpreter tab should point to JRuby.bat

Go to run -> run and give it about 30 seconds to load the JVM, the ruby environment, and hook everything in. Then check your http://localhost:3000/

To start debug execution then type debugger in the place you want to start the debugger.

It all starts off looking something like this:

Eclipse Ruby Debugger

How to debug ruby on rails in eclipse aptana plugin

Issue the following command from the command line:

gem install ruby-debug-ide

The error message is saying that you don't have this gem installed. It seems as though Aptana does not check to see what gems are installed before activating certain features.

In case you don't know what a gem is, think of it as a plugin that is installed system-wide.

How do I create a new ruby project in Eclipse indigo

Please follow the steps below.

  1. Install ruby

  2. Install eclipse (Ex: Eclipse Juno)

  3. Now, install Dynamic Languages Toolkit (DLTK)

    • In Eclipse go to Help -> Install New Software
    • Click on Add button
    • Enter Name as DLTK
    • Enter Location as http://download.eclipse.org/technology/dltk/updates/
    • Click ok
  4. Select the version and click on Next button

  5. Complete the installation

Enabling Ruby Perspective:

  1. In Eclipse go to Window -> Open Perspective

  2. Select Others..

  3. Select Ruby and click on Ok button

Note: You can save this perspective from Window -> Save Perspective As..

Adding Ruby Interpreter in Eclipse:

  1. In Eclipse goto Window -> Preferences

  2. Select Ruby -> Interpreters

  3. Click on Search button

  4. Select exe and click on Ok button

Hello World:

When above all setup is done correctly you should see Ruby Project in File -> New

  1. Create a new Ruby Project

  2. Add a new class file

  3. Enter puts "Hello World!!"

  4. Click on Ruby Script

  5. You should be able to see Hello World in the console

Happy Ruby learning!!!



Related Topics



Leave a reply



Submit