A journey to find those pieces of software or technology that facilitate productive and maintainable software development

Wednesday, October 29, 2008

Hello ErlIDE: Installation to Hello World

IDEs Don't Kill Code Bases, People Kill Code Bases

I have just gotten over my mental block for trying ErlIDE. The biggest conflict for me was that my exploration of Erlang was in part a rebellion against Java and IDE-centric programming. ErlIDE is an excellent solution for Erlang development. I now use it in lieu of TextMate and Vim for my desktop automation projects such as erlang_hgsvn which I use daily to merge SVN branches. Vlad Dumitrescu has created an excellent product and I will do my best to contribute in whatever way I can to its success.

Many people have had difficulty installing and using ErlIDE. This step by step guide will show how to install ErlIDE and make effective use of it so that it helps rather than frustrates you.

(Linux only) Allow Large Number of Open Files

When using Erlang it is generally advised to significantly raise the limit on the number of open files per process. Add the following lines to /etc/security/limits.conf (right above # End of file):

* soft nofile 1048576
* hard nofile 1048576

Install Erlang/OTP (if you have not already)

  • Ubuntu Linux: run the following in Terminal:
    sudo apt-get update
    sudo apt-get install erlang
  • Windows: run the Windows Installer for Erlang R12B-4
  • Mac OS X: install MacPorts and then run the following in Terminal:
    sudo port selfupdate
    sudo port install erlang

Install Eclipse and ErlIDE

  1. Download Eclipse IDE for Java Developers
  2. Extract it where you want to run it from (there is no installer, just an archive)
  3. Launch Eclipse by double-clicking eclipse (Linux), eclipse.exe (Windows), or Eclipse (Mac) in the eclipse folder
  4. Select Help (menu) → Software Updates... (a dialog will appear)
  5. Click Add Site...(another dialog will appear)
  6. Enter http://erlide.sourceforge.net/update into the Location field, then click OK (dialog will close)
  7. Select the checkbox by http://erlide.sourceforge.net/update and click Install... (another dialog will appear)
  8. Select Next
  9. Select I accept ... radio button and click Finish (a progress dialog will appear)
  10. (wait for confirmation dialog) Select Yes (Eclipse will restart)

Add Primary Erlang Runtime

Without these steps things like syntax highlighting, code completion and other significant aspects of the ErlIDE UI will not work properly. The IDE will function basically, but it will not work as intended.

  1. Select Window (menu) → Preferences... (Windows/Linux) or Eclipse (menu) → Preferences... (Mac) (a dialog will appear)
  2. Expand Erlang and select Installed runtimes
  3. Click Add... (a dialog will appear) and Enter Erlang in the Runtime name field
  4. Click Browse... and select the root of your Erlang/OTP install (mine is /opt/local/lib/erlang), then click OK (dialog will close)
  5. Click OK (preferences dialog will close)

Create Hello World Project

  1. (wait for Eclipse to restart) Select Window (menu) → Close All Perspectives
  2. Select Window (menu) → Open Perspective → Other... (a dialog will appear)
  3. Select Erlang and click OK (dialog will close and Erlang Perspective will load)
  4. In the Erlang Navigator bring up the context menu (right-click/control-click) and select New Erlang Project (a dialog will appear)
  5. Enter hello_world in the Project Name field and click Finish (dialog will close and hello_world project will appear in Erlang Navigator view)

Start Erlang Node To Run Code

  1. Select hello_world project, bring up the context menu and select Run As → Run Configurations... (a dialog will appear)
  2. Enter hello_world in the Name field
  3. Double-click Erlang application (a new confguration will appear in the right-hand panel)
  4. In the Main tab under Projects click the checkbox beside hello_world
  5. In the Runtimes tab click the checkbox beside Start the Erlang node if not running already and enter hello_world in the Node name field
  6. Click Run (dialog will close and Console will appear with hello_world Erlang node)
  7. Leave the Console running for the next part

Write Hello World Live!

  1. On the hello_world project bring up the context menu (right-click/control-click) and select New Module (dialog will appear)
  2. Enter hello_world in Module name field
  3. To the left of the Apply button, enter say_hello in the first box and 0 in the second box and click Apply
  4. Click Finish (dialog will close and an editor for hello_world.erl will be opened)
  5. In the Console type hello_world:say_hello().
  6. Oops! It displays ok and shows no greeting! Let's fix that
  7. In the hello_world.erl editor replace ok in say_hello with io:format("Hello World!") and save (Ctrl-S/Command-S)
  8. In the Console type hello_world:say_hello().
  9. Great! It displays "Hello World!" for us! Let's get it to say something else
  10. In the hello_world.erl editor replace "Hello World!" in say_hello with "Hello ErlIDE!") and save (Ctrl-S/Command-S)
  11. In the Console type hello_world:say_hello().
  12. Nifty! It displays "Hello ErlIDE!" for us! We can change the code at runtime.

Embrace Convention

When I first tried ErlIDE over a year ago I found the predetermined project structure irritating. I now realize that this project structure is an accepted convention in the Erlang community. It reflects the way that most Erlang/OTP applications are distributed.

Go With The Flow

Buy into ErlIDE's default project structure even though it can now be overridden. It will make it easier for you to work with ErlIDE and easier for other Erlang developers to use what you have created. We have had trouble using Eclipse integration for J2EE at work because of the non-standard layout of our projects. Make the right choice upfront and adopt the conventional Erlang project structure. I wish Joe had mentioned this in his book...

Understated Power Overstated Roughness

ErlIDE is much less rough around the edges than I would expect for a 0.3 release. It is also understating its capabilities and the quality of the Eclipse integration. There is definitely work to be done, but it is an excellent foundation.

ErlIDE is the best tool I have used for Erlang development. It is the clear winner in ease of use for comparable functionality. For anyone already familiar with Eclipse ErlIDE is familiar and comfortable to use. I think ErlIDE will be instrumental in getting more Java developers to use Erlang. I will be actively contributing whatever fixes and features I can to ErlIDE.

14 comments:

Serge said...
This comment has been removed by the author.
Serge said...

Hi Alain,
nice checklist - I will give it a shot. I am a VI junkie and happy so far, but that might change when it comes to large project - I know exactly what you mean.
Also it was great to read your post on the 8.11 problem - I was trying to get what did Joe mean in his book when posing that problem. Having your input as a starting point I came to my own conclusion, and your take on that would be interesting.
Thanks,
Serge

Unknown said...

Hi Serge,

Thank you for your kind words :)

Your solution to 8.11 is interesting. I had originally considered that approach. I like Ladislav Lenart's solution because there is no requirement of a registered process. For a tested solution for transactions I would look at things like mnesia and the global module. Kevin Smith's screencasts cover those topics well.

Regards,
Alain

Serge said...

Alain :)
of course you did. Seriously, as in OO, the dedicated object/process should do a particular job and handle concurrency. And the planned exception looks like a hack. But! This might be a reality in the complex project, so I accept the try/catch with the sigh...

oriste said...

Hi! Very nice article. I'm afraid I'm your worst nightmare: I'm new to Eclipse, new to ErlIDE and new to Erlang.

Running Mac OS X, 10.5.6, I have the Pragmatic Programming book on Erlang by my side and was going through the motions when I found your site and thought it a good idea to get some kind of IDE for Erlang.
Everything went fine up to "Start Erlang Node To Run Code", point 6. When I clicked on "Run" I go a series of messages saying:

{error_logger,{{2009,3,1},{15,54,44}},"** Connection attempt from disallowed node ~w ** ~n",['jerlide_250bafc@hulk']}

=ERROR REPORT==== 1-Mar-2009::15:54:44 ===
** Connection attempt from disallowed node jerlide_250bafc@hulk **
Eshell V5.6.4 (abort with ^G)
(hello_world@hulk.oriste.lan)1>
=ERROR REPORT==== 1-Mar-2009::15:54:45 ===
** Connection attempt from disallowed node jerlide_250bafc@hulk **
(hello_world@hulk.oriste.lan)1>
=ERROR REPORT==== 1-Mar-2009::15:54:45 ===
** Connection attempt from disallowed node jerlide_250bafc@hulk **
(hello_world@hulk.oriste.lan)1>

...and on and on and on...

In the above "hulk" is the name of my local machine, "oriste.lan" is my local domain.

I wondered if you could point me in the direction of where I need to look to remedy this: I have no idea if this is a problem with my network settings, with my Erlang configuration, with ErlIDE or Eclipse. All I want is to teach myself Erlang. Maybe you or your readership recognizes these error messages and can quickly help me out.

Thanks again for the article.

oriste said...

I found it! The error apparently was caused by the fact that I had my Eclipse installation in a folder whose name contained a space. After I deleted everything to start from scratch, I decided to NOT include a {space}-version number suffix in the folder name. I then re-did every step of your great tutorial and everything worked fine. Thanks again.

Unknown said...

I received error messages similar to those posted by oriste. I already had eclipse installed in a folder without any whitespaces.

SOLUTION:

Change the node name so that it was different than my workstations hostname. DOH! Works great now.

pking said...

Hi ,

I had a similar problem when I've set up new environment:

Connection attempt from disallowed node jerlide_ec81e30@wro00091b
I have tried different node names.

Finally, I have changed it to:
jerlide_ec81e30

and now works fine

Unknown said...

Unfortunately, since you don't tell anyone WHICH of the packages to install (there are approximately 10 choices) this pages doesn't help too much.

Unknown said...

Hi kevindtimm,

What operating system are you using?

This is a pretty old article. When it was written the commands worked to install directly. What specific problem are you seeing?

James Allen said...

Hi Alain, I'm trying to get erlIDE up and running for my OSX Snow Leopard, and everything installs correctly, at least I think so.

macports, erlang, Erlide plugin for Eclipse.

The problem I have is with the Console within Eclipse. I type in commands - hello_world:say_hello(). and nothing happens. I don't get any response within my console. Am I doing it wrong? I even tried running native erlang commands, like help(). and q(). and nothing. Thanks for the how-to, I can't wait till I get this working :D

James Allen said...

Nevermind, it turns out I had to restart Eclipse a couple times to get things working correctly. Now I get the console with all of erlang's glory!

Unknown said...

@James Allen:
Thank you for reading the article. I am glad you found a solution :)

James Allen said...

You bet. One thing that I should add, that when creating a new module, it doesn't automatically create the function, but rather only the exported function name, so erlide shows an error of an undefined function.

For people new to Erlang (such as myself) this was a bit confusing - perhaps a previous version of erlide automatically created the function when creating the module, I'm not sure. Thanks again!

SyntaxHighlighter