Eclipse Plugins for Ruby and OCaml
- If you haven't already done so, install Ruby 1.8.6 and Eclipse.
- From Eclipse's main menu, choose Help » Install New Software
- Next to the Work with field, choose Add...
- Choose a name like dltk (for Dynamic Languages Toolkit) and for location use
http://download.eclipse.org/technology/dltk/updates/. Click OK.
- Expand the "Dynamic Languages Toolkit (DLTK) 2.0" subtree, and check the following items:
- Dynamic Languages Toolkit - Core Frameworks
- Dynamic Languages Toolkit - Core Frameworks SDK
- Dynamic Languages Toolkit - Ruby Development Tools
- Dynamic Languages Toolkit - Ruby Development Tools SDK
- Click Next, Next, I accept, Finish, Yes to restart to accept the license and install the software.
- Once Eclipse has restarted, to open the Ruby perspective, choose Window » Open Perspective » Other and select Ruby.
- Now set up the ruby interpreter: Choose Window » preferences, expand the ruby subtree, and select interpreters.
- Click Add..., Browse... and navigate to your ruby executable (e.g. C:\ruby\bin\ruby.exe). Click OK, OK.
- Now you are ready to create a Ruby project: File » New » Ruby Project.
- Give it a name like myfirstruby and click Finish.
- Right click on the myfirstruby folder at the left, choose new empty ruby script and name it myfirstruby.
- In the editor region, type something like:
puts "Just a whisper. ".concat("I hear it in my ghost.")
- Select Run » Run As » Ruby Script. If all is well, you will see the output in the console.
The OCaml plugin has a nice ready-made interpreter built right into the Eclipse console (see below). Unfortunately this does not appear to be the case for Ruby. You are probably better off using irb by itself, but it is possible to get a poorly formatted irb running in the Eclipse console:
- Choose Run » External Tools » External Tools Configurations ....
- Right click Program and select New.
- Give it a name like irb_conf, and for location, Browse File system... and navigate to your ruby install directory again. Select the irb executable. On windows I had two files, irb (no extension) and irb.bat. The former gives an error but the latter runs.
- Click Apply and Run. Now you can use irb in the Eclipse console, although the » is missing from the prompt and all of your input gets echoed.
- If you haven't already done so, install Eclipse. As for OCaml, version 4.00 was reported to have issues with Eclipse. It is recommended that you use 3.11.0 for Windows and 3.12.0 for Mac OS X.
- In Eclipse, click Help » Install New Software...
- In Work with, enter http://www.algo-prog.info/ocaide then click Add, OK.
- Check OcaIDE and click Next, Next, I accept, Finish to accept the license and install the software. Eclipse will prompt you to accept unsigned code, you can click Yes.
- Click Yes to restart. After Eclipse restarts, choose Window » Open Perspective » Other... » OCaml.
- Go to Window » Preferences (Mac OS X users, go to Eclipse » Preferences).
- Expand the OcaIDE subtree and then click on Paths. If all the paths in this panel (except for possibly make and omake) are already filled in, then continue to the next step. Otherwise, click Browse next to OCaml Binaries Directory and choose the "bin" directory inside your OCaml installation directory (for example, C:\Program Files\ObjectiveCaml\bin). Then click Apply. Eclipse should fill in additional path values for you (ocaml, ocamlc, etc).
- Under Other tools » OCaml lib path, click Browse and choose the "lib" directory inside your OCaml installation directory. Press OK to close the dialog.
- Near the top right of Eclipse, you should see an OCaml button and Java button, with the Ocaml button selected. If you only see the Java button, click the button to the left which looks like a window with a yellow "+" sign, and then double click on "OCaml". Now you are in OCaml mode.
- Click the "Ocaml Toplevel" tab at the bottom of the workspace. Type into the prompt (do not type on the same line as the #; type below it at the bottom of the tab):
print_endline "hello world";;
. You should see the output:
hello world- : unit = ()
Creating and running OCaml projects in Eclipse
To create and run your OCaml projects, follow the steps below. If you are on windows and do not have Cygwin installed, you may get error messages about Cygwin at several steps, but you can safely ignore them (just click OK).
- Download the project files to your computer and note the file location.
- In OcaIDE within Eclipse, click File » New » OCaml Managed Project. Enter a name for "project name" and click Finish.
- Right click on the newly created project folder and click Import... » General » File System » Next.
- Click Browse, navigate to your download folder, and select the files to import.
- Click Finish. Now you can expand the project folder in Eclipse to see the files that were copied into your workspace as well as some OcaIDE-generated ones which are outlined in red.
- When you are ready to submit, make sure that you upload the final versions from your eclipse workspace, not the original versions you downloaded.
- To run your project, right click on the project folder and select Properties.
- Click Ocaml Project.
- Under "Make executable for:" check off the files that you want to compile. Leave "Compilation mode" as byte-code. Press Apply and OK to close the dialog.
- In your project, you should now see some new .exe files. If not, there is probably a compilation error in your code, so use the Toplevel to work out the kinks and try again.
- To run the executable, right click on it in Eclipse and select Run As » OCaml Executable. The output of the program should appear in the Console tab.