This article, a two part one, introduces IBM's "Eclipse" IDE. This was published in the "Linux For You" magazine in the July and August 2004 issues Visit LFY Website

The Eclipse IDE : Part 1

Eclipse has gained widespread acceptance as an excellent universal tool platform. This article, the first of a two part series, introduces the Eclipse IDE and its usage.


1. What is Eclipse?

The Eclipse Open Source Project was launched by IBM, Object Technology International and about eight other companies in November 2001. If you are interested in Java or are keen on open source projects, chances are that you have already heard some of the buzz surrounding Eclipse.

The aim of the Eclipse project was to deliver a high-quality platform that allowed incorporation of highly integrated software development tools. The entire project comprises of three projects: The Eclipse Project, The Eclipse Tools Project and The Eclipse Technology Project. The initial consortium of companies has grown immensely to include large software houses such as Borland, HP, Red Hat, SuSE, SAP, Oracle and several others.

fig1
Figure 1: The Eclipse IDE splash screen

So what is it that makes Eclipse different from any other commercial IDE? The answer lies in the fact that Eclipse is not an IDE for a particular development language or platform. In reality Eclipse is a "tool integration platform". Eclipse, not being tied to any particular language or platform, makes it very easy to allow integration of different tools to perform different tasks as plugins into a single consistent environment.

Eclipse is thus a base platform upon which almost any set of tools can be integrated. But this does not mean that the Eclipse IDE is nothing more than that. The standard Eclipse installation includes an excellent, integrated, full-featured Java IDE as well. The impressive features of this Java IDE rival those of any commercial Java IDE, and aptly demonstrate the flexibility of the Eclipse platform.

2. The Motivation behind Eclipse

The single most important reason for building yet another IDE was to create a "universal tool platform", "an IDE for anything and yet nothing in particular". But was this necessary at all?

The fact is that software development today involves using several separate tools for achieving tasks. For instance, a person typically uses an IDE for Java source files, another IDE for modeling, a different IDE for accessing CVS, and yet another IDE for designing HTML pages. What is worse, another person in the project team usually has a different set of preferred IDEs. This creates a rather messy situation wherein none of the (usually proprietary) development tools work together. Integration becomes a nightmare often requiring importing/exporting of files to/from proprietary formats.

Eclipse tries to solve this problem by providing a single platform that integrates all tools required for the job. For instance, Eclipse's JDT (Java Development Tools) includes an excellent assortment of such tools including an editor, a debugger, and several other advanced tools for development. Eclipse includes by default support for accessing CVS within its GUI. If a project requires the use of modeling tools or WSIWYG HTML editors, they can be "plugged in" seamlessly into Eclipse. This is the aspect that makes Eclipse shine as an extensible IDE. The entire project team can now use a single common platform for all its tasks. And the open source nature of the Eclipse platform implies that even you can write tools for integration into the Eclipse platform.

Since Eclipse itself is built using Java, if you want to write tools (commonly called "plugins") for extending Eclipse, you will have to write them in Java as well. Extending Eclipse will be taken up in the concluding part of this article. For now, we will concentrate on using Eclipse as an IDE in general and as a Java IDE in particular.

3. Getting and installing Eclipse
Eclipse is available from the download pages of http://www.eclipse.org. Eclipse is available for Linux, Windows 9X/ME/2000/NT/XP, Solaris etc. Eclipse for Linux comes in two flavours - one using GTK and the other using Motif.
fig2
Figure 2: The Eclipse.org Website

The most important pre-requisite of the Eclipse SDK is a Java Runtime Environment (JRE) which is not included in the download file. So, before trying to have a go at Eclipse, make sure you have a JRE installed. Additionally it is better if you have the JVM in your PATH, otherwise you will have to specify one with the "-vm" argument to the eclipse executable. Among Linux vendors, officially, Red Hat and SuSE are supported, but I have been using Eclipse on my Slackware 9.0 box, without any problems for quite a long time.

In this article, I have used Eclipse Release 2.1 (Linux x86/GTK). If you have a JRE and have extracted the Eclipse download archive to a folder, you can start Eclipse just by invoking the "eclipse" executable in the top-level directory (or simply clicking on it). If everything has gone properly, you should see an initial screen like the one shown in Figure 3.

fig3
Figure 3: The first splash screen

Installation is as simple as that. Note however that in a Linux style environment, if you want all users to use Eclipse, it is recommended to install Eclipse into a read-only directory from the non-root users perspective (such as /opt/eclipse or /usr/share/eclipse) and then use separate "workspaces" (working directories) for each user. In this case the working directory must be specified with the -data parameter. Thus in my system for example, eclipse is invoked as follows:

/opt/eclipse/eclipse -data /home/raj/eclipse

If everything goes well, you will be presented with the initial graphical environment (shown in Figure 4).

fig4
Figure 4: The Eclipse IDE
4. Eclipse as a universal IDE

The first screen thrown at you consists of several panes having labels such as "Navigator", "Outline", "Tasks" and so on. Describing the usage of all such components of the Eclipse IDE would take up a book by itself, hence that is not attempted here. But to understand the Eclipse interface, you do need to understand three basic UI concepts: Editors, Views and Perspectives.

In Eclipse, you normally work in your workspace, which is basically a directory in your file system which contains the resources (files) that you view or modify. Editors allow you to create and modify resources. The editor used usually depends on the type of resource you are working on. For instance the editor invoked for a plain text file will differ from the one invoked for a Java source file. The latter supports the usual bells and whistles you would expect from any commercial Java editor such as syntax highlighting and automatic indentation, but the former doesn't.

Views are, loosely speaking, the panes that are visible in the IDE apart from the Editors. Views exist to present some information to the user. You can navigate through your resources by using the "Navigator" view. If you are editing a Java source file, then its imports, class hierarchy, members and methods are available in the "Outline" view. Resources can also be changes from some views. This happens when, for example, you rename a resource from the "Navigator" view.

A Perspective is nothing but a set of views and editors arranged in a particular initial layout for accomplishing a specific type of task. When you start Eclipse for the first time, it opens in the "Resource" perspective. This perspective includes views such as "Navigator", "Outline", "Tasks" and so on. When you switch to the "Debug" perspective, ( Window->Open Perspective->Other->Debug ), you will see views entitled "Variables", "Debug", "Console" - all of which are typically associated with the job of debugging source code. Again, when you switch to the Install/Update perspective, ( Window->Open Perspective->Other->Install/Update ), a completely different set of views ("Initial Configuration", "Feature Updates" etc) show up, as shown in Figure 5.

fig5
Figure 5: The Install/Update Perspective

Well, its now time to fiddle around within the Eclipse IDE. Start by creating a new project ( File->New Project ). Choose the type "Simple" for now. Give it a name, and upon clicking Finish , your project should end up in the "Navigator" view. Right click on the project name, and select New->File . Insert different types of files in your project in this manner. Double clicking on the file in the "Navigator" fires up the appropriate Editor. Try editing a plain text file and a Java file to see the difference in the capabilities of the two editors.

If you do not like the way things are in your current perspective, you might try switching to a different one. If you just want to remove view or two, simply close their windows. You may add a view to the current perspective as well ( Window->Show View ). When you have finally realized that you have messed up things too much, click on Window->Reset Perspective.

Support for CVS is nicely integrated into Eclipse. Switch to the "CVS Repository Exploring" perspective and you'll see what I mean. To add a CVS repository right-click on the "CVS Repositories" view and click on New->Repository Location . Fill in the fields in the window that shows up and click finish to access your CVS server easily from within Eclipse.

If you want to change some aspects of Eclipse, you can do so by accessing the Preferences window ( Window->Preferences ). This is the common point from which all configurable options of the Eclipse IDE and all its plugins may be viewed or modified. Eclipse also has an integrated help system that is quite comprehensive.

By now you probably have an idea of the goal behind Eclipse - that of an integrated platform for all tasks.

5. Eclipse JDT: Eclipse as a Java IDE

The Eclipse Java Development Tools (JDT) are plugins to the base Eclipse platform. The JDT, as I have stated before, need not be downloaded separately as it is included in the standard Eclipse zipped archive. These tools come into action automatically when you are dealing with Java projects or Java based resources. In this section, let us see what the Eclipse JDT has to offer for Java developers.

Create a new Java project ( File->New->Project->Java ). Type in "HelloWorld" as the project name (yes, the familiar "Hello World" program yet again) and click on Finish. You will be asked to switch to the "Java" perspective, which is a good idea in this case. Right-click on the project in the "Package Explorer" view and create a new class ( New->Class ). You will be presented with a dialog like the one shown in Figure 6.

fig6
Figure 6: The "New Java Class" Dialog

In the Name field, type in HelloWorld and remove the java.lang.Object from the Superclass field. Put a check against creating the method stub for public static void main(String[] args) and remove the check against Inherited Abstract Methods . Make sure the class is "public". Upon clicking finish, you should end up with an editor showing HelloWorld.java. The "Outline" view now shows the class hierarchy for the HelloWorld class. The class and the main method can now be seen in the file open in the editor. Add the following line inside the main method:

System.out.println("Hello World!");

As you typed the above line did you notice the following two things ?

  • A red underline appears under the statement as you type, but it vanishes after you have typed the complete statement (assuming you have made no errors in typing it). When you type a statement, Eclipse actually invokes its very own incremental compiler in the background, which underlines the statements it considers wrong. This is an excellent way of quickly finding and correcting syntax and other errors in your source code, without having to save and compile the file each time.
  • If you pause momentarily after typing "System.", you get a popup window that suggest completions for what you were typing. This feature, called "Code Assist" or "Content Assist" may be manually invoked by pressing Ctrl+Space at any time in your editing session.

Okay, now our simple Java program is ready to be run. To do this, click Run->Run... and double click on "Java Application". This creates a new run configuration for the HelloWorld project. Here you may specify various parameters such as arguments, the JRE to use, the classpath and so on. This dialog is shown in Figure 7.

fig7
Figure 7: The HelloWorld Run Configuration

If all goes well, you should see the "Console" view in the IDE showing the output of our program ("Hello World!").

We have barely scratched the surface of what the Eclipse JDT has to offer for Java developers. Let us look at a few of the more advanced features of the JDT.

Code Generation

We have already seen some of this in action while creating the HelloWorld class. The JDT also allows creating and configuring packages, interfaces and so on. Further, the JDT allows you to override and implement methods (which create skeletons for the methods), generate "getters" and "setters" for class attributes, generate delegate methods, add constructors of the parent class and so on. All these are available from the context menu of the editor ( Source submenu). The JDT also automates adding Javadocs to your sources.

Error Correction

The JDT has a "Quick Fix" option that is quite a nifty tool for correcting mistakes. For example, in your main method of HelloWorld.java type in the following

Var = 10;

You will see a red underline beneath "Var", indicating a compile error for that portion of the line. Now click on Edit->Quick Fix. A small popup shows you some fixes for the error. Beside each option, another popup shows you a preview of what changes shall be made to your source code if you select that fix. Select "Create local variable "Var" to correct the error.

Source Code Refactoring

Refactoring refers to making very significant code changes to your project without affecting the behaviour of the program in any way. In the JDT, moving fields, methods, classes or renaming classes, methods, packages and so on can be done effortlessly thanks to its refactoring support. The refactoring tools may be accessed by clicking on the element to refactor from the "Outline" view and selecting the appropriate refactor option from its context menu (for example, Refactor->Change Method Signature... ).

The Scrapbook

Another useful feature of the JDT is the scrapbook, which as the name suggests, is an editor for evaluating and trying out Java code snippets. A scrapbook can be created by right clicking on the project in the "Package Explorer", and creating a new "Scrapbook page". It is a file with a .jpage extension, which opens up in the editor just like any normal text file. You can type statements in this page (without creating classes and so on). For instance, type the following in the editor, select the whole line and click on "Display" from the context menu:

"hello" + "world"

You should get the following result in the scrapbook page:

(java.lang.String) helloworld

Powerful Debugging Support

The debugging capabilities of the JDT are quite unparalleled. A glance at the Java Debug perspective will convince you of this fact. The JDT supports Hot Code Replace , a feature in the newer JREs (such as 1.4) that allows change in the code while it is executing to fix errors. This avoids the need to restart the buggy program over and over again.

More features

The JDTs list of features seem to be never ending. Eclipse has an extensive search mechanism by virtue of which you may search for all types of Java elements (types, methods, implementers, references, fields, to name a few). There are other additional perspectives especially suited for Java projects such as the "Java Browsing" perspective and the "Java Type Hierarchy" perspective.

6. Beyond the JDT

If you are a Java developer, I believe you will be quite interested in Eclipse to give it a try. But if you are not, then do not worry. The wonderful thing about Eclipse is that it is not just the JDT. If you are a C/C++ developer, then download the CDT (C/C++ Development Tools) from http://www.eclipse.org for free, and then try out Eclipse. Plugins for almost everything are available from sites such as http://eclipse-plugins.info . From visual GUI builders to chat applets, its all there.

Eclipse can be exactly what you want it to be. By adding your own plugins, you can make Eclipse do and act the way you want it to. I'll get to this interesting aspect in the next and concluding part. Till then, happy experimenting with Eclipse.



Continue to part 2 of this article

Copyright (c) 2004 Rajorshi Biswas
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation. A copy of the license is included here.