My Adventures in Coding

February 11, 2009

Erlang – Getting Started and Using Eclipse

Filed under: Erlang — Brian @ 9:19 pm
Tags: , ,

Recently for fun I have been doing some recreational development in Erlang. I have put together a small set of notes here to help anyone else who is just getting started in Erlang, especially if you want to have some fun and use the Eclipse Erlang plugin!

Getting Started

Now when I was first starting to learn the language, I went through this tutorial: Introduction to Erlang. It walks you through the basic language structures such as Atoms, Tuples, and Lists. Also the final page of the tutorial shows you how to create a simple client and server for a chat room in Erlang. The amount of code required to write such an application is significantly shorter than what would be required to do the equivalent in Java or C#.

When I first started Erlang development I used Ubuntu Linux. The setup was very easy. Just open the Ubuntu software installer, search for “Erlang” and select install. That was all. Then to start the emulator all I had to do was type “erl” at a command prompt and that was it. It is important to note that the only folder the emulator will look in for MyProgram.erl files is in the folder from which the emulator was started.

NOTE: You can find a guide to all of the commands available in the Erlang shell at the official Erlang “Getting Started” tutorial.

Setup Eclipse and Erlang (On Windows)

I ran into a few snags while trying to do Erlang development in windows, so this is a quick document explaining how to do the proper setup with Eclipse. All of the instructions I found online left out a several important steps.

  1. Install Erlang, the windows binary can be obtained from  http://erlang.org/download.html
  2. Add the Erlang bin folder to your windows system path

    1. Control Panel -> System -> Advanced Settings ->  Environment Variables
    2. Under “System Variables” append PATH with the folder where Erlang was installed

      1. e.g.,  C:\Program Files\erl5.6.5\bin;
  3. Install Eclipse, any version will do, even the basic Java/Eclipse bundle
  4. Install the Erlang pluggin for Eclipse called “Erlide”

    1. Open Eclipse
    2. Help -> Software Updates -> Available Software
    3. Cick the button “Add Site” and enter the following URL

      1. http://erlide.sourceforge.net/update
      2. Click “OK”
    4. Now you should see the URL in the “Name” list under “Available Software”
    5. Expand the Erlide Update section and select “Stable builds”
    6. Now click the “Install” button in the upper right hand corner
    7. When the installation is finished restart Eclipse
  5. Now you will need to configure Eclipse to know the location of where Erlang was installed on your system

    1. Open Eclipse
    2. Window -> Preferences -> Erlang -> Installed Runtimes

      1. Click “Add” and select the path to the root Erlang install folder

        1. e.g., C:\Program Files\erl5.6.5\
      2. Click “OK”
      3. Restart Eclipse
  6. Now your setup should be complete

Creating an Erlang Project in Eclipse

There were a few little things that I missed when setting up a project that were not mentioned in any set of instructions I found. So here is a complete set of instructions to setup an Erlang project.

  1. File -> New -> Project
  2. Erlang -> Erlang Project
  3. Give the project a name e.g., “HelloWorld”
  4. Click “Next then click “Finish”
  5. Now, the project is created, but you won’t yet be able to compile
    1. Run -> Run Configurations
    2. Right click on “Erlang Application” and select “New”
    3. In the first tab titled “Main” select your project “HelloWorld”
    4. On the tab “Runtimes” ensure
      1. Runtime = Erlang
      2. Node name = erlide
    5. Now for the most important part, go to the “Environment” tab
      1. Click “Select”
      2. select “PATH”
      3. click “OK”
    6. Now click “Apply” and close the window
  6. You are now all setup!!!

Running an Erlang Project in Eclipse

One of the coolest things about developing Erlang code in Eclipse is that when you click “Run” it not only compiles all *.erl src files in the open Erlang project, but it also opens the Erlang emulator in “Console” where you can now type any command you want, run any function created in any of your *.erl projects and it will just work. No need to code in Eclipse then have to run your Erlang programs from the command prompt and no need to have to compile each *.erl file individually. Very slick!

From the Command Prompt

Now if all you want to do is use Erlang from the command prompt in windows, thats easy. Just open a command prompt and type “erl” and the emulator will open. Also you can just load the Erlang editor from the windows start menu (Start -> All Programs -> Erlang OTP – Erlang. The emulator works fine, however from here you will only be able to cut and paste code you want to run, you will not be able to open an existing erlang code file. To do this you will need to use the command prompt.

  1. So open a command prompt
  2. cd to the folder where the file is and type “erl”
    1. Now the emulator is open and you will have access to any files in the current directory.
  3. So now if you have the file “hello.erl” in that folder and want to execute this application
    1. c(hello). –This will compile the program
    2. hello:hello(). –This will execute the module “Hello” and function inside it also called “hello”

February 9, 2009

Where is the maven release for Jersey-Spring 1.0.1?

Filed under: REST — Brian @ 1:46 pm
Tags: ,

Just before the Jersey 1.0.1 release was made, the module structure was changed from

com.sun.jersey
to
com.sun.jersey.contribs

This caught us recently when we wanted to reference version 1.0.1 in our pom.xml file. We could only find 1.0.1-SNAPSHOT at:

http://download.java.net/maven/2/com/sun/jersey/jersey-spring/

Then we realized we needed to be using:

http://download.java.net/maven/2/com/sun/jersey/contribs/jersey-spring/

So we updated our pom.xml file dependency to the following:


<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.0.1</version>
</dependency>

I hope this post helps you out!

Blog at WordPress.com.