Thursday, June 07, 2007

Groovy Programming with Eclipse - 1

In this short series of Groovy posts, I intend to cover some Groovy fundas and at the same time myself learn the platform. I will work on Eclipse and would not work at console level and instead use Groovy plugin on Eclipse.
1. Installing Groovy Plugin for Eclipse.
  • Start Eclipse. Go to Help->Software Updates->Find and Install.
  • Select "Search for new features to install" and click Next.
  • Click on "New Remote Site"
  • Give a name say "Groovy Plugin" and in the URL put "http://dist.codehaus.org/groovy/distributions/update/"
  • Click Ok. Now select the newly added remote site and then click Finish. Follow the on-screen instructions and majorly you need to click "Install All" and then restart Eclipse for the changes to be effected.

2. Testing your Groovy installation on Eclipse.

  • Create a new project in Java.
  • Now in the Package Explorer right click on the project. You should see a "Groovy" item in the context menu.
  • So go to the Groovy item in the context menu and go to "Groovy->Add Groovy Nature".
  • Doing this would kind of convert our Java project to Groovy project. We can now run and test our Groovy programs.
  • Now right click on the project and create a new package. Say "groovy.learning.samples".
  • Then right click on the project and click on "New->Other". Type Groovy in the "type filter text" textbox. Now select "Groovy Class" and give it a name.(Tutorial1).
  • Type the following line inside the code block already generated. Essentially you see a main already inserted.
    "println("Welcome to Groovy World");
  • Save the file. Now go to the menu "Run->Run As->Groovy Application". You should be able to see the message printed in the console. If so , you have successfully installed Groovy plugin on eclipse and good to write your Groovy programs.

This post, I hope, gives a quickstart to get started working with Groovy on Eclipse. In the subsequent posts, I hope to cover other basic programming constructs in Groovy.

1 comment:

Anonymous said...

ThankYou very much for the guidance.
Earlier I was struggling to get my small groovy program run in eclipse platform.
Your guidance helped me.
Thankyou very much.

--Sridevi.